Hi,
I have a strange problem.
Firstly let me figure out my classes.
class IQueable //abstract class, i.e. interface
{
virtual int GetPriority() = 0; //pure virtual fnc.
};
class CQueue()//real class; implemented
{
void Enqueue( IQueable* apElem );
IQueable* Dequeue( IQueable* apElem );
...
};
class CBaseTask //real base class; implemented
{
int GetStatus();
void SetStatus( int anStat );
int m_nStatus; //default is initialized 0.
};
//real multi-inherited class; implemented
class CDerivedQueableTask : public CBaseTask, public IQueable
{
virtual int GetPriority(){ return 2; };
...
}
void main()
{
CQueue* pQueue = new CQueue();
CDerivedQueableTask* pTask = new CDerivedQueableTask();
pTask->SetStatus( 1 );
//the above task is deriven from IQueable
pQueue->Enqueue( pTask );
CBaseTask* pBT = (CBaseTask*)pQueue->Dequeue();
//the above base is not deriven from IQueable,
//but I am sure that it is CDerivedQueableTask which implemets IQueable.
//it is just a few line above...
pBT->GetStatus(); //returns some meaningless value; e.g. 701356
}
As you see if I cast the dequeued object( CDerivedQueableTask ) to CTask, I get inconsistent result.
If I change it to the following, it works!
CDerivedQueableTask* pTask = (CDerivedQueableTask*)pQueue->Dequeue();
What may be the problem ?
