提高:线程 - 编译器错误 [英] boost:thread - compiler error
本文介绍了提高:线程 - 编译器错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用boost ::线程在我的计划,但得到以下编译器错误(Visual Studio 2005中):
错误1 **错误C2064 **:术语不计算为函数取0
参数D:\\ ... \\ boost_1_37_0 \\提升\\螺纹\\详细\\ thread.hpp 56
因此,我试图重新在一个小程序的问题,并从的本网站。
我的测试code现在看起来是这样的。为什么它不是一个类的内部工作:
的#include<升压/ thread.hpp>
#包括LT&;&iostream的GT;
一流的HelloWorld
{
上市:
你好无效();
无效条目();
};无效的HelloWorld ::条目()
{
提高::线程THRD(安培;的HelloWorld ::你好);
thrd.join();
}无效的HelloWorld ::你好()
{
性病::法院LT&;< 世界,你好,我是一个线索! <<的std :: ENDL;
}INT主(INT ARGC,CHAR *的argv [])
{
*的HelloWorld BLA =新的HelloWorld;
bla->条目();
返回0;
}
解决方案
尝试像这样 - 升压::线程的构造函数期待一个boost :: function0(其中一个函数指针,而是一个成员函数指针不时,由于该指针)。
无效的HelloWorld ::条目()
{
提高::线程THRD(的boost ::绑定(安培;的HelloWorld ::你好,这个));
thrd.join();
}
I wanted to use boost::thread in my program, but get the following compiler error (Visual Studio 2005):
Error 1 **error C2064**: term does not evaluate to a function taking 0
arguments d:\...\boost_1_37_0\boost\thread\detail\thread.hpp 56
Therefore I tried to recreate the problem in a small program and modified the working Hello World example from this site.
My test code now looks like this. Why is it not working inside a class?:
#include <boost/thread.hpp>
#include <iostream>
class HelloWorld
{
public:
void hello();
void entry();
};
void HelloWorld::entry()
{
boost::thread thrd(&HelloWorld::hello);
thrd.join();
}
void HelloWorld::hello()
{
std::cout << "Hello world, I'm a thread!" << std::endl;
}
int main(int argc, char* argv[])
{
HelloWorld *bla = new HelloWorld;
bla->entry();
return 0;
}
解决方案
Try it like this - the boost::thread constructor is expecting a boost::function0 (which a function pointer is, but a member function pointer isn't, due to the this pointer).
void HelloWorld::entry()
{
boost::thread thrd(boost::bind(&HelloWorld::hello,this));
thrd.join();
}
这篇关于提高:线程 - 编译器错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文