2013-02-10 110 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