g ++ 4.7을 C++ 11 플래그와 함께 사용하고 있습니다. 이 데모에서 :C++ 11 std :: thread가 함수로 컴파일되지만 클래스가 아닙니다.
#include <iostream>
#include <thread>
class do_work
{
public:
void operator()()
{
std::cout << "Doing work..." << std::endl;
}
};
void foo()
{
}
int main()
{
// Does not work
std::thread t(do_work);
t.join(); // error: request for member ‘join’ in ‘t’, which is of non-class type ‘std::thread(do_work)’
// Works
std::thread t2(foo);
t2.join();
return 0;
}
내가 성공적으로 호출 할 생성자의 인수로 함수를 만든 스레드에서()에 가입 할 수 있습니다,하지만 난()에 가입했다 스레드에 (오류 인라인 참조) 호출 할 수 없습니다 생성자 인수로 펑터로 생성됩니다. 아무도 이것을 설명 할 수 있습니까?
[C++ : "클래스 X 유형이 아닌 Y의 멤버 X에 대한 요청"의 기괴한 발생] (http://stackoverflow.com/questions/11138543/c-bizarre-occurrence-of- x-of-y-of-non-class-type 회원 요청) – ecatmur