[英]How to get std::chrono::time_point clock type
I have a class with a std::chrono::time_point member. 我有一个带有std :: chrono :: time_point成员的类。 In one of the class functions I want to create another time_point with the same clock type.
在一个类函数中,我想创建另一个具有相同时钟类型的time_point。
How do I take the clock type from my member? 如何从会员那里获取时钟类型?
I tried doing: 我试着做:
std::chrono::time_point<std::chrono::system_clock> m_time_point;
std::chrono::time_point<m_time_point.clock> new_tp(some_duration)
but this results with an error: cannot refer to type member 'clock' in 'std::chrono::time_point' with '.' 但这会导致错误:无法用'。'引用'std :: chrono :: time_point'中的类型成员'clock'。
std::chrono::time_point
is a template, not a type. std::chrono::time_point
是模板,而不是类型。 So you can't have a member with this type, it has to be instantiated with some type of the clock. 因此,您不能拥有这种类型的成员,必须使用某种类型的时钟实例化它。 Assuming you have it, and you member name is
m_time_point
, getting to clock is trivial: 假设您拥有它,并且您的成员名称是
m_time_point
,那么开始计时很简单:
using clock_t = decltype(m_time_point)::clock;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.