thread_ = boost::thread( boost::function< void (void)>( boost::bind( &clientTCP::run , this ) ) );
是否可能 run 有这样的参数:
void clientTCP::run(boost:function<void(std::string)> func);
如果是的话应该如何编写我的 boost::thread 调用
谢谢。
最佳答案
以下代码 boost::bind( &clientTCP::run , this )
定义了一个函数回调。它在当前实例 (this
) 上调用函数 run
。使用 boost::bind,您可以执行以下操作:
// Pass pMyParameter through to the run() function
boost::bind(&clientTCP::run, this, pMyParameter)
在此处查看文档和示例:
http://www.boost.org/doc/libs/1_46_1/doc/html/thread/thread_management.html
If you wish to construct an instance of boost::thread with a function or callable object that requires arguments to be supplied, this can be done by passing additional arguments to the boost::thread constructor:
void find_the_question(int the_answer);
boost::thread deep_thought_2(find_the_question,42);
希望对您有所帮助。
关于c++ - 如何将参数传递给 boost::thread?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5730747/