|
-
January 13th, 2004, 10:35 AM
#1
multiple inheritance casting problems
Hi Guys,
have programmed myself into a corner!
/////////////////////////////////////////////////////////////////
Struct Left
{
virtual void LeftFunc() = 0;
};
typedef vector<Left*> LeftVector;
Struct Right
{
virtual void RightFunc() = 0;
};
typedef vector<Right*> RightVector;
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.
Any help very much appreciated.
Many thanks,
LJHW
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|