C++ 如何获取std::chrono::time\u点时钟类型
我有一个包含std::chrono::time\u point成员的类。在其中一个类函数中,我想创建另一个具有相同时钟类型的时间点 如何从我的会员处获取时钟类型 我试着做:C++ 如何获取std::chrono::time\u点时钟类型,c++,C++,我有一个包含std::chrono::time\u point成员的类。在其中一个类函数中,我想创建另一个具有相同时钟类型的时间点 如何从我的会员处获取时钟类型 我试着做: std::chrono::time_point<std::chrono::system_clock> m_time_point; std::chrono::time_point<m_time_point.clock> new_tp(some_duration) std::chrono::time\u
std::chrono::time_point<std::chrono::system_clock> m_time_point;
std::chrono::time_point<m_time_point.clock> new_tp(some_duration)
std::chrono::time\u point m\u time\u point;
std::chrono::时间点新时间点(某些持续时间)
但这导致了一个
错误:无法使用“”引用“std::chrono::time_point”中的类型成员“clock”。
std::chrono::time_point
是一个模板,而不是类型。所以不能有这种类型的成员,它必须用某种类型的时钟进行实例化。假设您拥有它,并且您的成员名称是m_time_point
,那么到达时钟是很简单的:
using clock_t = decltype(m_time_point)::clock;