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

时间:2019-01-14 14:49:56

标签: c++

我有一个带有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'

1 个答案:

答案 0 :(得分:4)

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

using clock_t = decltype(m_time_point)::clock;