将线程指针绑定到对象时出错

时间:2014-01-21 23:37:12

标签: c++ boost smart-pointers

我正在用C ++做类似的事情:

typedef boost::shared_ptr<boost::thread> thread_pointer;
Class myClass {

   // ......
   thread_pointer my_ptr;
}

myClass::function1 {
   my_ptr = new boost::thread(&myClass::function2, this);
}

但它表示运营商'='没有匹配。即使我使用boost :: bind,我也会收到错误。

1 个答案:

答案 0 :(得分:4)

构造函数是显式的,所以你需要

my_ptr = thread_pointer(new boost::thread(&myClass::function2, this));

my_ptr.reset(new boost::thread(&myClass::function2, this));

这假设您首先需要一个指针。