Probleme cast vers type reel.
Bonjour,
Je dispose d'une class abstraite AThread:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13
|
class AThread
{
private:
bool _started;
pthread_t _thread;
public:
AThread();
virtual ~AThread();
void start();
virtual void callback() = 0;
}; |
La methode start est chargée de lancer le thread.
La methode callback doit etre implemente par les class qui herite de AThread; celle-ci est la methode que le thread doit appeller.
Pour ce faire, j'ai cree une fonction:
Code:
1 2 3 4 5 6 7 8 9 10 11 12
|
extern "C"
{
void *thread_func(void *mem)
{
AThread *obj;
obj = static_cast<AThread *>(mem);
obj->callback();
return (NULL);
}
} |
Cette fonction est donc appellee comme ceci:
Code:
1 2 3 4 5 6 7 8 9
|
void AThread::start()
{
if (!this->_started)
{
this->_started = true;
pthread_create(&this->_thread, NULL, thread_func, this);
}
} |
Cependant lors d'un appel a la methode start, la methode thread_func appelle la methode callback de l'objet AThread dans tous les cas.
J'ai essaye de static_cast ver le type reel, de passer la reference du type reel a thread_func mais le resultat reste le meme:
Citation:
pure virtual method called
terminate called without an active exception
Aborted