2013-02-10 105 views
2

我使用boost::asio::steady_timer _timer演绎,但我发现,如果使用-std = C++ 11的标志,编译器将报告在无法转换类型错误:C++ 11型与ASIO

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

,无运算符+()的匹配函数为:

_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配置问题?

回答

5

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

这是记录的here