简体   繁体   English

C ++ 11的C ++编译问题

[英]C++ compile issue with c++11

I am trying to compile a few C++ files from a make file. 我正在尝试从make文件中编译一些C ++文件。 I keep on getting this error: 我继续收到此错误:

<i> no member named 'to_time_t' in
      'std::__1::chrono::steady_clock'; did you mean
      'std::chrono::system_clock::to_time_t'? 
    time_t tnow = std::chrono::high_resolution_clock::to_time_t(now);

</i>

Then after some research I found out that this is because I'm not using c++ 11. I'm on a MAC OS X 10.10.2. 然后经过一番研究,我发现这是因为我没有使用c ++11。我使用的是MAC OS X 10.10.2。 So I installed brew and then installed gcc and g++ 4.9 using brew. 因此,我安装了brew,然后使用brew安装了gcc和g ++ 4.9。 However, I still get the same error. 但是,我仍然遇到相同的错误。 Any suggestions? 有什么建议么? This code runs on a linux machine. 此代码在Linux机器上运行。

Any help would be appreciated. 任何帮助,将不胜感激。

to_time_t is a member of system_clock , but not (necessarily) of steady_clock or high_resolution_clock . to_time_t是其成员system_clock ,但不是(一定) steady_clockhigh_resolution_clock You are using high_resolution_clock , which on your system, going by the error message, appears to be an alias of steady_clock , not of system_clock . 您使用的是high_resolution_clock ,在系统上,按照错误消息显示,该别名似乎是steady_clock的别名,而不是system_clock的别名。 If the code is working for you on another platform, it could be that on that platform, high_resolution_clock is an alias for system_clock , but you can't rely on this always being the case. 如果代码在另一个平台上为您工作,则可能是在那个平台上, high_resolution_clocksystem_clock的别名,但是您不能总是这样。

The solution is to just use system_clock , if you wan't a time_t from it. 解决的办法是只使用system_clock ,如果你wan't一个time_t从它。 system_clock should be at least as high resolution as time_t , so using a potentially higher resolution clock here doesn't buy you anything. system_clock分辨率至少应与time_t一样高,因此在此处使用可能更高分辨率的时钟不会为您带来任何收益。 Or just use the std::time function in the first place, if you simply want the current time. 或者,如果仅需要当前时间,则首先使用std::time函数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM