I have
auto now = std::chrono::high_resolution_clock::now();
and i want to pass it to a function using a general type for a time point. I do not want specify the resolution or type of clock used.
I've tried using
void my_function(std::chrono::time_point time_point);
but without success. Since apparently std::chrono::time_point isn't a type.
The std::chrono::time_point
is a templated class, that needs at least a clock
template parameter.
Either explicitly set the clock, like
void my_function(std::chrono::time_point<std::chrono::high_resolution_clock> time_point);
Or you can make your function a template itself:
template<typename Clock>
void my_function(std::chrono::time_point<Clock> time_point);
In the last case you actually don't have to specify the template parameter when calling the function, the compiler figures it out for you:
my_function(now);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With