Mayerz Mayerz - 1 year ago 278
C++ Question

Problems with std::chrono

I am having trouble compiling with chrono, here is the code:


#include <chrono>

class Time
std::chrono::steady_clock::time_point _start_t;
std::chrono::steady_clock::time_point _now;
std::chrono::steady_clock::time_point _time;
Time(const Time &other);
Time &operator=(const Time &other);
void start();
double getDurSec();
double getDurMilSec();
void setNow();

Compilation error:

g++ -W -Wall -Wextra -I./include -std=c++0x -c -o src/Time/Time.o src/Time/Time.cpp
In file included from src/Time/Time.cpp:11:0:
./include/Time/Time.hh:21:3: error: ‘steady_clock’ in namespace ‘std::chrono’ does not name a type
./include/Time/Time.hh:22:3: error: ‘steady_clock’ in namespace ‘std::chrono’ does not name a type
./include/Time/Time.hh:23:3: error: ‘steady_clock’ in namespace ‘std::chrono’ does not name a type
src/Time/Time.cpp: In member function ‘void Time::start()’:
src/Time/Time.cpp:34:2: error: ‘_time’ was not declared in this scope
src/Time/Time.cpp:34:23: error: ‘std::chrono::steady_clock’ has not been declared


Tell me if you need more informations.

Answer Source

You are probably using a g++ version prior to 4.7.0 where std::chrono::steady_clock was not implemented. If this is the case, you have two solutions:

  • Upgrade your g++ to 4.7.0 or a more recent version.
  • Use instead the old std::chrono::monotonic_clock.
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download