Multiple Inheritance problem

in Help Center
We are having an issue whereby we cannot compile using Ice-generated classes and C++ multiple inheritance.
Let me try to describe:
IceA
|
Bar---IceB
Bar derives from two Ice-generated classes, IceA and IceB. Bar will not compile, however, because each of the Ice_generated classes defines __gcClear(), __gcReachable, etc and these virtual methods clash in Bar. Using virtual base classes does not work because IceA and IceB are different classes.
This is actually a simplified version of our hierarchy and I will not go into the specifics of why we are designing this way, but is there a way around this problem assuming the above class hierarchy?
Thanks,
Brian
Let me try to describe:
IceA
|
Bar---IceB
Bar derives from two Ice-generated classes, IceA and IceB. Bar will not compile, however, because each of the Ice_generated classes defines __gcClear(), __gcReachable, etc and these virtual methods clash in Bar. Using virtual base classes does not work because IceA and IceB are different classes.
This is actually a simplified version of our hierarchy and I will not go into the specifics of why we are designing this way, but is there a way around this problem assuming the above class hierarchy?
Thanks,
Brian
0
Comments
If your Slice classes don't have data members, then make them interfaces in Slice. Define a new interface that derives from both of them, and then implement this interface in your code.
If your Slice classes are really classes, i.e., have data members, then you cannot use inheritance. If Slice would allow this, then languages that don't support multiple inheritance (such as Java) could not be used.
Thanks for the reply. Let me be more specific...
--> The problem arises with C++. IceA and IceB are, in fact, interfaces in slice, but are generated by slice2cpp as non-abstract classes that derive from ::Ice::Object and then define various methods like __gcClear(). Because slice2cpp generates the same virtual methods in IceA and IceB, this causes the clash problem noticed by the compiler.
Define a new interface that derives from both of them, and then implement this interface in your code.
--> Don't really want to get into the why of our design, but suffice to say that we need to implement our base class, Foo, from IceA and a derived class, Bar from IceB. Notice that I say "implement" in the way one would implement an interface in Java. In Java, this does not seem to be a problem.
IceA
|
Foo IceB
\ /
Bar
If your Slice classes are really classes, i.e., have data members, then you cannot use inheritance. If Slice would allow this, then languages that don't support multiple inheritance (such as Java) could not be used.
--> Both Slice definitions are trivial, one-method, interfaces, but as you know, are generated in C++ as concrete classes.
--> Does this help you understand the problem better? I suspect we cannot get around this, but thought I'd ask in case you had an idea for a workaround.
For your example, the inheritance graph could look like this:
You must use virtual inheritance everywhere for this to work.
I fixed my problem. Thanks for you help.
Appreciate it.
Brian