我有一个带[]运算符重载的类。我也有一个线程可以开始...... 如何将[]绑定到线程?
我试过了:
threadpool.schedule( bind( static_cast< MyClass (MyClass::*)(const MyClass &arg )>( &MyClass::operator[]), arg ) )
但VS2008说:
错误C2664:
'boost::threadpool::thread_pool::schedule': cannot convert parameter 1 from 'boost::_bi::bind_t' to 'const boost::function0 &'
我该如何解决这个问题?提前谢谢。
答案 0 :(得分:1)
看起来不对劲。您的成员函数仍然接受一个参数。所以你需要一个占位符,或者你忘了绑定this
threadpool.schedule( bind(
static_cast< MyClass (MyClass::*)(const MyClass &arg )>(&MyClass::operator[]),
this, arg ) )
接受其类类型的operator[]
看起来有点奇怪。下面是一个示例,它应该如何查找“通常”的下标运算符
threadpool.schedule( bind(
static_cast< MyClass (MyClass::*)(std::size_t)>(&MyClass::operator[]), this, index )
);