繁体   English   中英

如何获取std :: chrono :: time_point时钟类型

[英]How to get std::chrono::time_point clock type

我有一个带有std :: chrono :: time_point成员的类。 在一个类函数中,我想创建另一个具有相同时钟类型的time_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_point'中的类型成员'clock'。

std::chrono::time_point是模板,而不是类型。 因此,您不能拥有这种类型的成员,必须使用某种类型的时钟实例化它。 假设您拥有它,并且您的成员名称是m_time_point ,那么开始计时很简单:

using clock_t = decltype(m_time_point)::clock;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM