duplicate: "pure virtual method called" when implementing boost :: thread wrapper interface
I am trying to create a more object oriented version of streams using boost streams.
So, I created the Thread class:
class Thread {
public:
Thread() {}
virtual ~Thread() { thisThread->join(); }
void start() { thisThread = new boost::thread(&Thread::run, this); }
virtual void run() {};
private:
boost::thread *thisThread;
};
this class creates a stream in start () for example:
thisThread = new boost::thread(&Thread::run, this);
The problem is that when I create a class that overwrites a method run(), the method run()from Thread is a thread call instead of a new methodrun()
for example, I have a class that extends Thread:
class CmdWorker: public Thread {
public:
CmdWorker() : Thread() {}
virtual ~CmdWorker() {}
void run() { }
};
when i do
Thread *thread = new CmdWorker();
thread.start(); //---> calls run() from Thread instead of run() from CmdWorker
but for clarity:
thread.run(); calls the correct run from CmdWorker, (run() is virtual from Runnable)
Any idea why this is happening and how it can be fixed?
Note: I created a function (which has nothing to do with the Thread class)
void callRun(Thread* thread) {
thread->run();
}
and changed the thread creation to:
thisThread = new boost::thread(callRun, this);
, thread Thread CmdWorker
EDIT:
: http://ideone.com/fqMLF
http://ideone.com/Tmva1
( , )
boost