I want to cast object hlaObj to HlaObject from RtiValueAggregate but it's not working...! There is no inheritance between two classes. and HlaObject is virtually derived from RtiValue. can anyone tell me whats wrong with the following code: Thanks!
class RtiValue;
class HlaObject;
class RtiValueAggregate
{
public:
friend class RtiValue;
int w;
RtiValueAggregate() : w(10)
{
}
};
class RtiValue
{
public:
friend class RtiValueAggregate;
RtiValue()
{
int x = 5;
pAggregate_ = new RtiValueAggregate();
}
RtiValueAggregate* getAggregate() const
{
return pAggregate_;
}
private:
RtiValueAggregate* pAggregate_;
};
class ObjectAttribute : public RtiValue
{
public:
int v;
ObjectAttribute() : v(0)
{
RtiValue();
}
};
class HlaObject :public virtual RtiValueAggregate
{
public:
int a;
ObjectAttribute* ptrV;
HlaObject() : a(1)
{
ptrV = new ObjectAttribute();
}
};
int _tmain(int argc, _TCHAR* argv[])
{
RtiValue *rtiVal = new RtiValue();
RtiValueAggregate* rtiValueAggr = rtiVal->getAggregate();
HlaObject *hlaObj = reinterpret_cast<HlaObject*>(rtiValueAggr);
cout << "Press any key to exit..." << endl;
cin.get();
return 0;
}