
From outside the function operator()(), I can have the pointer to
I have a strange problem with the code below. thread object 'thread'.
From inside operator()() 'thread' is always 0.
Why does this happen? ------------------------------------------------------------------ #include <cstdio> #include <boost/thread/thread.hpp> class A { boost::thread *thread; public: A() : thread(0) {} ~A() { join(); } void createThread() { thread = new boost::thread(*this); } void operator()() { printf("Starting thread with pointer: %d\n", thread); //<<<<<<<<<<<<<<HERE! delete thread; thread = 0; } void join() { if (thread) thread->join(); } }; int main(int, char**) { A a; a.createThread(); a.join(); return 0; } ------------------------------------------------------------------