스레드 함수에 인수를 전달하려고했지만 수행 할 수 없었습니다. 나는 그것에 대해 읽으려고했지만 (Passing multiple arguments to a threaded function) 나는 아직도 그것을 알아낼 수 없었다.멀티 스레딩 C++ 함수에 인수 전달
#include <iostream>
#include <thread>
using namespace std;
void func(int t)
{
cout << t << endl;
}
int main()
{
thread t1(func,4);
t1.join();
return 0;
}
내가이 수행하여 (나는 문제가 넣다 zsh을 사용) 명령 행에서이를 실행 : 여기 내 코드입니다
g++ test.cpp
./a.out
을하지만 이러한 오류를 가지고 :
thread_test.cpp:14:12: error: no matching constructor for initialization of 'std::__1::thread'
thread t1(func,4);
^~~~~~~
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/thread:379:9: note: candidate constructor template not viable: requires single argument '__f', but
2 arguments were provided
thread::thread(_Fp __f)
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/thread:268:5: note: candidate constructor not viable: requires 1 argument, but 2 were provided
thread(const thread&);
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/thread:275:5: note: candidate constructor not viable: requires 0 arguments, but 2 were provided
thread() _NOEXCEPT : __t_(0) {}
^
1 error generated.
을
이 중요한 경우 OSX 10.11.4와 함께 Mac을 사용하고 있습니다.
또한 컴파일 할 C++의 버전을 확인하려면 이 명령을 실행하고 넣어 이것을 가지고 :
g++ --version
로 구성 : --prefix =/응용 프로그램/Xcode.app/내용/개발자는/usr --with-Gxx라는-포함-DIR =/응용 프로그램/엑스 코드. 애플 LLVM 버전 7.3.0 (clang-703.0.31) 대상 : x86_64- 사과 darwin15.4.0 스레드 모델 : POSIX InstalledDir : /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
재생할 수 없음 : http://ideone.com/BFRbzc. 어떤 컴파일러를 사용하고 있습니까? –
[정상 clang과 함께 작동] (http://coliru.stacked-crooked.com/a/f95035aaa16f9fc4), 그래서 아마 애플은 다시 무언가를 망쳤습니다. 그래도 좋은 테스트 케이스. –
[가능한 복제본] (http://stackoverflow.com/questions/22031640/thread-in-c-in-macos-x)'--std = C++ 11' (또는 더 높은). –