【发布时间】:2013-04-08 12:59:28
【问题描述】:
我试图通过回调运行 boost::thread 一些对象函数
在A类中有这样一个函数:
void DoWork(int (*callback)(float))
{
float variable = 0.0f;
boost::this_thread::sleep(boost::posix_time::seconds(1));
int result = f(variable);
}
在主要:
int SomeCallback(float variable)
{
int result;
cout<<"Callback called"<<endl;
//Interpret variable
return result;
}
int main(){
A* file = new A();
boost::thread bt(&A::DoWork, file , &SomeCallback );
cout<<"Asyns func called"<<endl;
bt.join();
cout<<"main done"<<endl;
}
boost::thread bt(&A::DoWork, file , &SomeCallback ); 行导致 链接器 错误。我从本教程中接听的电话:
http://antonym.org/2009/05/threading-with-boost---part-i-creating-threads.html.
错误是:
unresolved external symbol "public: void __thiscall A::DoWork(int (__cdecl*)(float))" (?DoWork@A@@QAEXP6AHM@Z@Z) referenced in function _main
这段代码有什么问题?
【问题讨论】:
-
callback曾经在DoWork中使用过吗? -
您可能对 boost.asio 感兴趣,以满足您的异步需求。
-
@DrewDormann 我猜这是一个拼写错误/复制错误 -
f和callback很可能是相同的。 -
是的,再次复制出现问题
标签: c++ boost asynchronous