【问题标题】:Problems with std::chronostd::chrono 的问题
【发布时间】:2013-05-13 09:25:48
【问题描述】:

我在用 chrono 编译时遇到问题,这里是代码:

时间.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();
};

编译错误:

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

等等……

如果您需要更多信息,请告诉我。

【问题讨论】:

标签: c++ c++11 compilation g++ chrono


【解决方案1】:

您可能使用的是 4.7.0 之前的 g++ 版本,其中未实现 std::chrono::steady_clock。如果是这种情况,您有两种解决方案:

  • 将您的 g++ 升级到 4.7.0 或更高版本。
  • 改用旧的std::chrono::monotonic_clock

【讨论】:

  • [12:09]camill_a@/home/camill_a[4]$ g++ -v [...] gcc 版本 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5)
  • g++4.7 是广泛使用的版本吗?这个稳定吗?我目前正在以这种方式安装它askubuntu.com/questions/168947/how-to-upgrade-g-to-4-7-1
  • 最后一个评论,单调和稳定有什么区别?
  • @Mayerz 认为自己很幸运。我的学校仍然使用 g++ 3.4 :)
  • @Mayerz - monotonic_clockchrono 规范的早期草案。它被 steady_clock 取代,它具有更有用的语义。
猜你喜欢
  • 1970-01-01
  • 2020-01-05
  • 2014-03-23
  • 2017-09-02
  • 2013-10-25
  • 1970-01-01
  • 2020-10-13
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多