I need to declare the following variable in a class:
auto gameStartClock = std::chrono::high_resolution_clock::now();
However, I receive this error message from gcc 5.1.0
(with C++11 enabled) whenever I try to do that:
<file>.hpp:274: error: non-static data member declared 'auto'
auto gameStartClock = std::chrono::high_resolution_clock::now(); ^
non-static data member declared 'auto'
So I guess the error will be gone after I replace auto
by the correct type. However, every example I found out there about ::now()
uses auto
.
What is its type?
Note: I tried std::chrono::time_point
with a few templates but got no success. Not sure which are the correct ones.
std::chrono::high_resolution_clock::now Returns a time point representing with the current point in time.
std::chrono::system_clock::now Returns a time point representing with the current point in time.
Class std::chrono::high_resolution_clock represents the clock with the smallest tick period provided by the implementation. It may be an alias of std::chrono::system_clock or std::chrono::steady_clock, or a third, independent clock.
Chrono in C++ Measure execution time with high precision in C/C++ Measure execution time of a function in C++
The type is std::chrono::time_point<std::chrono::high_resolution_clock>
.
From the manual: http://en.cppreference.com/w/cpp/chrono/high_resolution_clock/now
Edit: As pointed out by Lightness Races in Orbit in the comments, you can also use std::chrono::high_resolution_clock::time_point
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