這個簡單的例子未能在VS2K8編譯:你如何正確使用boost :: make_shared_ptr?
io_service io2;
shared_ptr<asio::deadline_timer> dt(make_shared<asio::deadline_timer>(io2, posix_time::seconds(20)));
這個例子也一樣:
shared_ptr<asio::deadline_timer> dt = make_shared<asio::deadline_timer>(io2);
的錯誤是:
錯誤C2664:「提高:: ASIO :: basic_deadline_timer :: basic_deadline_timer(boost :: asio :: io_service &,const boost :: posix_time :: ptime &)':不能將參數1從'const boost :: asio :: io_服務」到‘的boost :: ASIO :: io_service對象&’
非常好,謝謝!不知道有關boost :: ref。部分原因是爲了避開這種類型的東西,還是有其他用途? – ApplePieIsGood 2010-03-11 14:07:45
@蘋果:它的設計非常出於這個原因。例如,'boost :: thread'會爲新線程創建一個參數副本,但是如果您想實際傳遞一個參考'boost :: ref',那麼它也可以在那裏工作。它用於任何時候你想傳遞一個引用,但函數打算做一個副本。 – GManNickG 2010-03-11 18:08:56