Hi!
I have a slightly trickier tree of classes (and I worry it cannot be simpler).
The root class is a simple interface, call it
IRoot. It declares a pure virtual function, lets say
virtual int foo() = 0;
, nothing more.
There is one more interface,
IInterface, extending
IRoot abstract class by some other pure virtual functions.
Class
TRoot implements (extends)
IRoot interface and adds a number of new methods. This class therefore is not abstract, the foo() function is implemented.
Then I have a class
TDescendent extending both
TRoot and
IInterface, it does not add a new functionality:
1 2
|
class TDescendent: public TRoot, public IInterface {
}
| |
I would think that everything is ok - the foo() function is declared in an ancestor of both classes (TRoot, IInterface) and in one of them (TRoot) has been implemented.
The reality differs, though. The compiler says that TDescendent is abstract because a pure virtual function foo() is present.
I know a possible solution:
1 2 3
|
class TDescendent: public TRoot, public IInterface {
virtual int foo() { return TRoot::foo(); }
}
| |
But I do not like that because it seams the TDescendent::foo() function CAN differ from TRoot::foo() (unless everyone can see the body of the function). I would prefere ?SOME? declaration that TDescendent::foo() function IS THE SAME as TRoot::foo(), the best would be if I even would not have to declare it in TDescendent because it was ?SOME WAY? implicit.
Do you understand what I'm trying to solve? Do you have any suggestion?
Thank you in advance,
yman