2

我正在使用boost::asio::steady_timer _timer,但我发现如果使用 -std=c++11 标志,编译器将在以下位置报告无法转换类型的错误:

boost::asio::steady_timer::time_point now() {
    return boost::asio::steady_timer::clock_type::now();
}

并且在以下位置没有 operator+() 的匹配函数:

_timer.expires_at(now()+boost::chrono::milliseconds(100));

似乎编译器无法在 c++11 模式下推断出正确的类型。但相反我使用

boost::asio::basic_waitable_timer<boost::chrono::steady_clock> _timer;

并更改boost::asio::steady_timer::time_pointboost::chrono::steady_clock::time_point

没关系。但是,它们是相同的,并且在没有 0x 或 11 模式的 g++ 中可以正常工作。

C++11 对 typedef 推断有什么不同吗?还是boost配置问题?

4

1 回答 1

5

该类basic_waitable_timer可以使用std::chronoboost::chrono。在最近的 g++ 上,它std::chrono默认使用。要强制使用boost::chrono,请定义BOOST_ASIO_DISABLE_STD_CHRONO.

这记录在这里

于 2013-02-10T10:45:11.923 回答