boost::thread Problem
-
Hallo
Ich benutze Visual C++ 2010 und boost 1.43.0
Beim ersten Beispiel motzt der Compiler:
"main.cpp|16|error C2228: left of '.join' must have class/struct/union"#include <iostream> #include <boost/thread.hpp> struct F { void operator ()() { std::cout << "hello\n"; } }; int main() { boost::thread t(F()); t.join(); return 0; }
Geht:
#include <iostream> #include <boost/thread.hpp> struct F { void operator ()() { std::cout << "hello\n"; } }; int main() { boost::thread t = boost::thread(F()); t.join(); return 0; }
Weiss jemand den Grund dafür? Der typ von t ist ja in beiden Fällen gleich.
Danke!
-
explicit-Magie.
class thread : private boost::noncopyable // Exposition only { public: // construct/copy/destruct thread(); explicit thread(const boost::function0<void>&);
-
Einfach mal die Warnungen anschauen:
main.cpp(14): warning C4930: 'boost::thread t(F (__cdecl *)(void))': prototyped function not called (was a variable definition intended?)
-
life schrieb:
Einfach mal die Warnungen anschauen:
main.cpp(14): warning C4930: 'boost::thread t(F (__cdecl *)(void))': prototyped function not called (was a variable definition intended?)
Die Warnung kommt bei mir nur wenn ich das join() weglasse.
@Zeus
Aber das ist doch keine implizite Umwandlung:boost::thread t(F());
-
Das ist eine Funktionsdeklaration, falls das immer noch nicht klar geworden war..
-
Hrrrm, okay. Ich wusste gar nicht dass Funktionsdeklarationen im Code erlaubt sind.