简体   繁体   中英

How to get std::chrono::time_point clock type

I have a class with a std::chrono::time_point member. In one of the class functions I want to create another time_point with the same clock type.

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 is a template, not a type. 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:

using clock_t = decltype(m_time_point)::clock;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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