Struct Concrete1
: public Left, public Right
{
virtual void LeftFunc() {...}
virtual void RightFunc() {...}
};
Struct Concrete2
: public Left, public Right
{
virtual void LeftFunc() {...}
virtual void RightFunc() {...}
};
// I need to store objects as type Left*
LeftVector lv;
lv.push_back(new Concrete1());
lv.push_back(new Concrete2());
// I have another vector from which I need to use the Right methods from these objects
// I need to be able to do the following say
for ( i = 0; i < rv.size(); ++i )
rv[i]->RightFunc();
// How do I put them in?
Left * c1 = lv[0];
Left * c2 = lv[1];
RightVector rv;
rv.push_back( ??c1?? );
rv.push_back( ??c2?? );
I have tried
rv.push_back( reinterpret_cast<Right*>(c1) );
rv.push_back( reinterpret_cast<Right*>(c2) );
This compiles but crashes as if the functions are not being found properly in the class.
Left has to be a base class in its own right, ie. it can't derive from Right which would solve the problem easily.
Think I must be a bit tired and over-worked.
It's as simple as
// How do I put them in?
Left * c1 = lv[0];
Left * c2 = lv[1];
RightVector rv;
rv.push_back( dynamic_cast<Right*>(c1) );
rv.push_back( dynamic_cast<Right*>(c2) );
Bookmarks