[Virtual sur pthread] ne vas pas dans la méthode surchargé
Bonjour
je rencontre un problème étonnant
j'ai la classe template
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| #include <pthread.h>
#if !TFUNCTION
#define TFUNCTION
template<class T> void *startThread(void *arguments)
{
Thread<T>* thread = (Thread<T>*)arguments;
thread->function();
pthread_exit(NULL);
return NULL;
}
#endif
template<class T> class Thread {
public:
Thread() { }
~Thread() { }
void Start() {
pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
pthread_create(&threadid, &attr, startThread<T>, (void *)this);
}
T& GetValue() { return value; }
public:
virtual void function() {
int vv = 0;
};
private:
pthread_t threadid;
pthread_attr_t attr;
T value;
}; |
que je dérive de la façon suivante
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13
| struct Data {
public:
string s;
int i;
};
class XThread : public Thread<Data> {
protected:
virtual void function()
{
cout << "Starting XThread " << endl;
}
}; |
et que j'utilise
Code:
1 2 3 4 5
| XThread x;
x.GetValue().i = 25;
x.GetValue().s = "test string";
x.Start();
int vv = 0; |
je pensais naïvement (sans doute) que la virtualisation marcherait mais la manifestement pas
auriez vous une solution ?