【问题标题】:In boost::posix_time, how to construct time_duration from volatile time_duration?在 boost::posix_time 中,如何从 volatile time_duration 构造 time_duration?
【发布时间】:2014-06-27 10:21:44
【问题描述】:

我正在尝试编译这段代码:

#include <boost/date_time.hpp>
using boost::posix_time::time_duration;
int main()
{
  volatile time_duration t0;
  time_duration t1 = t0;
  return 0;
}

使用这个命令:

g++ test01.cpp -std=c++11 -I /boost_1_55_0/ -o test01

我得到这个错误:

test01.cpp:6:22: error: no matching function for call to ‘boost::posix_time::time_duration::time_duration(volatile boost::posix_time::time_duration&)

我使用的是 gcc 4.8.2;知道如何解决这个问题吗?

【问题讨论】:

  • 你想通过声明volatile来达到什么目的?
  • 或许这与this bug有关?
  • @BartoszKP 我使用的是 gcc 版本 4.8.2,而错误似乎在 gcc 4.3 中。
  • @e271p314:从那条评论中我可以看出你只阅读了页面下方的 30%。 阅读整个错误历史记录。

标签: c++ boost volatile


【解决方案1】:

这是由于a GCC bug。像这样解决它:

volatile time_duration t0;
time_duration t1 = const_cast<time_duration&>(t0);

之所以有效,是因为const_cast 可以消除波动性和恒定性。请注意,我不确定这有多安全。

另一种解决方法是首先摆脱volatile;如今,它很少有任何用途。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-10-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-19
    • 2017-11-30
    相关资源
    最近更新 更多