Ich versuche, Threads für meine C++ - Anwendung zu verwenden.Kompilieren von C++ - Threads
Mein Code ist:
#include <iostream>
#include <thread>
class C
{
public:
void * code(void * param)
{
std::cout << "Code thread executing " << std::endl;
return NULL;
}
};
int main()
{
C c;
std::thread t (&C::code, &c);
t.join();
}
Beim Kompilieren, ich habe diese Fehler:
In file included from /opt/centos/devtoolset-1.0/root/usr/lib/gcc/x86_64-redhat-linux/4.7.0/../../../../include/c++/4.7.0/bits/move.h:57:0,
from /opt/centos/devtoolset-1.0/root/usr/lib/gcc/x86_64-redhat-linux/4.7.0/../../../../include/c++/4.7.0/bits/stl_pair.h:61,
from /opt/centos/devtoolset-1.0/root/usr/lib/gcc/x86_64-redhat-linux/4.7.0/../../../../include/c++/4.7.0/bits/stl_algobase.h:65,
from /opt/centos/devtoolset-1.0/root/usr/lib/gcc/x86_64-redhat-linux/4.7.0/../../../../include/c++/4.7.0/bits/char_traits.h:41,
from /opt/centos/devtoolset-1.0/root/usr/lib/gcc/x86_64-redhat-linux/4.7.0/../../../../include/c++/4.7.0/ios:41,
from /opt/centos/devtoolset-1.0/root/usr/lib/gcc/x86_64-redhat-linux/4.7.0/../../../../include/c++/4.7.0/ostream:40,
from /opt/centos/devtoolset-1.0/root/usr/lib/gcc/x86_64-redhat-linux/4.7.0/../../../../include/c++/4.7.0/iostream:40,
from C.cpp:1:
/opt/centos/devtoolset-1.0/root/usr/lib/gcc/x86_64-redhat-linux/4.7.0/../../../../include/c++/4.7.0/type_traits: In instantiation of 'struct std::_Result_of_impl<false, false, std::_Mem_fn<void* (C::*)(void*)const>, C*>':
/opt/centos/devtoolset-1.0/root/usr/lib/gcc/x86_64-redhat-linux/4.7.0/../../../../include/c++/4.7.0/type_traits:1857:12: required from 'class std::result_of<std::_Mem_fn<void* (C::*)(void*)const>(C*)>'
und vieles mehr ...
Ich Kompilieren mit:
g++ -std=c++0x C.cpp
Die Compiler-Version:
$g++ --version
g++ (GCC) 4.7.0 20120507 (Red Hat 4.7.0-5)
Was mache ich falsch?
Sie fehlen einen Parameter für den Funktionscode beim Erstellen des Threads – Niall
Btw, das ist eine ausgezeichnete erste Frage. Klares, reproduzierbares Beispiel. Vollständige Compilerdetails auch. Gut gemacht. – Barry