Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the type of std::chrono::high_resolution_clock::now() in C++11?

Tags:

c++

c++11

auto

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.

like image 707
thiagowfx Avatar asked Jul 19 '15 02:07

thiagowfx


People also ask

What does std :: Chrono :: high_resolution_clock :: now return?

std::chrono::high_resolution_clock::now Returns a time point representing with the current point in time.

What does std :: Chrono :: System_clock :: now return?

std::chrono::system_clock::now Returns a time point representing with the current point in time.

What is Chrono high_resolution_clock?

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.

What is Chrono header file for in C++?

Chrono in C++ Measure execution time with high precision in C/C++ Measure execution time of a function in C++


1 Answers

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

like image 117
developerbmw Avatar answered Nov 07 '22 23:11

developerbmw