是否有可能將std :: unique_ptr作爲參數傳遞給boost :: thread構造函數?如果不是,什麼是最好的解決方法?boost :: thread和std :: unique_ptr
一個小例子:
// errors: g++ uniqueptr_thread.cpp -std=c++0x
#include <iostream>
#include <memory>
#include <boost/thread.hpp>
class TestThread{
public:
void operator()(std::unique_ptr<int> val){
std::cout << "parameter: " << val << std::endl;
}
};
int main(int argc, char* argv[]){
std::unique_ptr<int> ptr(new int(5));
boost::thread th(new TestThread(), std::move(ptr));
}
與哪個編譯器? g ++ 4.4.5給了我比boost版本更長的錯誤列表,使用相同的選項(-std = C++ 0x) – Dutow
@Dwowo:根據C++ 0x,它應該可以工作。如果沒有,那麼你的GCC或libC++版本可能有問題。也許嘗試更近一個? –
我在Mac OS X上使用了clang + libC++(http://llvm.org/),非常接近它們兩者的開發小技巧。 –