Hello...
Just For Fun... Im Writing a small Game Engine Based on SDL, and im having loads of trouble trying to write a Thead abstract class.
I'm at work at the moment, and dont have access to my code, but the design is like so....
Code:
class IThread
{
public:
virtual void Main(void)=0;
void Start(IThead *This);
};
int ThreadStarter(void *thread)
{
if(thread!=NULL)
{
IThread *Thread = reinterpret_cast<IThread*>(Thread);
Thread->Main();
}
}
void IThread::Start(IThread* This)
{
SDL_CreateThread(ThreadStarter, This);
}
I Then Inherit From The IThread Class to create my Background Thread, The Background Thread Implements the virtual Main() of IThread, and calls Start with the this pointer as a parameter.
My Problem is, The ThreadStarter's Call to main Always attempts to run the Virtual Main, Not The Background threads Main().
Whats Going Wrong ???
I Assume the reinterpret_cast is messing up the vtable ???
But How Else Can i Cast a void pointer to an IThread ???
Can Anyone point out is wrong / how to fix it ?
or surgest a better way of implementing a thread class with SDL ???
Thanks !