【发布时间】:2011-06-11 11:10:31
【问题描述】:
我尝试使用 boost 调用带参数的函数,但它不起作用。代码是这样的
void Simulate::cr_number_threaded(lint nodes) {
for(lint i = 0; i < trials_per_thread; i++) {
// code
}
}
void Simulate::run_cr_number() {
vec_cr_number.clear();
boost::thread t[threads];
for(int i = 0; i < n_s.size(); i++) {
// n_s[i] is the current number of nodes
for(int t_idx = 0; t_idx < threads; t_idx++)
t[t_idx] = boost::thread(cr_number_threaded, n_s[i]);
// etc...
}
}
我得到的错误如下:
Simulate.cpp:在成员函数'void 模拟::run_cr_number()': Simulate.cpp:27:错误:没有匹配 调用函数 'boost::thread::thread(, long int&)'
更新: 我听从了建议。使用我得到的第一个解决方案
Simulate.cpp:在成员函数'void 模拟::run_cr_number()': Simulate.cpp:28:错误:没有匹配 调用'bind(, long int&)'的函数 ../../boost_1_44_0/boost/bind/bind.hpp:1472: 注:候选人是: boost::_bi::bind_t::type> boost::bind(F, A1) [with F = void (模拟::*)(lint), A1 = long int] ../../boost_1_44_0/boost/bind/bind.hpp:1728: 注意:
boost::_bi::bind_t::type, boost::_mfi::dm, 类型名称 boost::_bi::list_av_1::type> boost::bind(M T::*, A1) [with A1 = 长整数,M = void ()(lint),T = 模拟]
使用第二个我得到了这个
Simulate.cpp:在成员函数'void 模拟::run_cr_number()': Simulate.cpp:28:错误:没有匹配 调用函数 'boost::thread::swap(boost::_bi::bind_t, boost::_bi::list2, boost::_bi::value > >)' ../../boost_1_44_0/boost/thread/detail/thread.hpp:310:注意:候选人是:void boost::thread::swap(boost::thread&)
【问题讨论】:
标签: c++ multithreading function boost