Problems with std :: chrono

I had a problem compiling with a cron, here is the code:

Time.hh

#include <chrono> class Time { protected: std::chrono::steady_clock::time_point _start_t; std::chrono::steady_clock::time_point _now; std::chrono::steady_clock::time_point _time; public: Time(); Time(const Time &other); Time &operator=(const Time &other); ~Time(); public: void start(); double getDurSec(); double getDurMilSec(); private: 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 

Etc ...

Tell me if you need more information.

+6
source share
1 answer

You are probably using g ++ version up to 4.7.0, where std::chrono::steady_clock not implemented. If so, you have two solutions:

  • Upgrade your g ++ to 4.7.0 or later.
  • Use the old std::chrono::monotonic_clock .
+10
source

Source: https://habr.com/ru/post/944859/


All Articles