std :: thread错误(线程不是std的成员) [英] std::thread error (thread not member of std)
问题描述
我编译&安装gcc4.4使用macports。
I compiled & installed gcc4.4 using macports.
当我尝试编译使用 - > g ++ -g -Wall -ansi -pthread -std = c ++ 0x main.cpp。 ..:
When I try to compile using -> g++ -g -Wall -ansi -pthread -std=c++0x main.cpp...:
#include <thread>
...
std::thread t(handle);
t.join();
....
编译器返回:
cserver.cpp: In member function 'int CServer::run()':
cserver.cpp:48: error: 'thread' is not a member of 'std'
cserver.cpp:48: error: expected ';' before 't'
cserver.cpp:49: error: 't' was not declared in this scope
但 std :: cout<< ...
任何人都可以帮助我?
推荐答案
gcc尚未完全支持std :: thread:
gcc does not fully support std::thread yet:
http:/ /gcc.gnu.org/projects/cxx0x.html
http://gcc.gnu.org/onlinedocs/libstdc++/manual/status.html
使用 boost::thread 。
编辑
虽然下面的代码用gcc 4.4.3编译并运行良好:
Although the following compiled and ran fine for me with gcc 4.4.3:
#include <thread>
#include <iostream>
struct F
{
void operator() () const
{
std::cout<<"Printing from another thread"<<std::endl;
}
};
int main()
{
F f;
std::thread t(f);
t.join();
return 0;
}
编译
g++ -Wall -g -std=c++0x -pthread main.cpp
code> a.out :
Output of a.out
:
Printing from another thread
你能提供完整的代码吗?也许在 ...
s中有一些模糊的问题潜伏在
Can you provide the full code? Maybe there's some obscure issue lurking in those ...
s?
这篇关于std :: thread错误(线程不是std的成员)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!