我有一个结构体,其中包含一个std::chrono::system_clock::time_point
struct NetInfo {
std::chrono::system_clock::time_point time;
std::chrono::steady_clock::time_point start;
};
当我尝试将std::chrono::system_clock::now()
的结果分配给时间点之一时
api::NetInfo ni;
ni.start = std::chrono::system_clock::now();
我遇到了一个很大的错误。
/home/rootkid/rendu/cpp2/cpp_zia/lib/NetService/src/NetService.cpp:48:51: error: no match for ‘operator=’ (operand types are ‘std::chrono::_V2::steady_clock::time_point {aka std::chrono::time_point<std::chrono::_V2::steady_clock, std::chrono::duration<long int, std::ratio<1, 1000000000> > >}’ and ‘std::chrono::_V2::system_clock::time_point {aka std::chrono::time_point<std::chrono::_V2::system_clock, std::chrono::duration<long int, std::ratio<1, 1000000000> > >}’)
ni.start = std::chrono::system_clock::now();
^
In file included from /usr/include/c++/7.2.1/thread:38:0,
from /home/rootkid/rendu/cpp2/cpp_zia/lib/NetService/./include/NetService.h:3,
from /home/rootkid/rendu/cpp2/cpp_zia/lib/NetService/src/NetService.cpp:1:
/usr/include/c++/7.2.1/chrono:610:14: note: candidate: constexpr std::chrono::time_point<std::chrono::_V2::steady_clock, std::chrono::duration<long int, std::ratio<1, 1000000000> > >& std::chrono::time_point<std::chrono::_V2::steady_clock, std::chrono::duration<long int, std::ratio<1, 1000000000> > >::operator=(const std::chrono::time_point<std::chrono::_V2::steady_clock, std::chrono::duration<long int, std::ratio<1, 1000000000> > >&)
struct time_point
^~~~~~~~~~
/usr/include/c++/7.2.1/chrono:610:14: note: no known conversion for argument 1 from ‘std::chrono::_V2::system_clock::time_point {aka std::chrono::time_point<std::chrono::_V2::system_clock, std::chrono::duration<long int, std::ratio<1, 1000000000> > >}’ to ‘const std::chrono::time_point<std::chrono::_V2::steady_clock, std::chrono::duration<long int, std::ratio<1, 1000000000> > >&’
/usr/include/c++/7.2.1/chrono:610:14: note: candidate: constexpr std::chrono::time_point<std::chrono::_V2::steady_clock, std::chrono::duration<long int, std::ratio<1, 1000000000> > >& std::chrono::time_point<std::chrono::_V2::steady_clock, std::chrono::duration<long int, std::ratio<1, 1000000000> > >::operator=(std::chrono::time_point<std::chrono::_V2::steady_clock, std::chrono::duration<long int, std::ratio<1, 1000000000> > >&&)
/usr/include/c++/7.2.1/chrono:610:14: note: no known conversion for argument 1 from ‘std::chrono::_V2::system_clock::time_point {aka std::chrono::time_point<std::chrono::_V2::system_clock, std::chrono::duration<long int, std::ratio<1, 1000000000> > >}’ to ‘std::chrono::time_point<std::chrono::_V2::steady_clock, std::chrono::duration<long int, std::ratio<1, 1000000000> > >&&’
我在这里做错了什么?