I have three classes that inherit as follows:
Class_A
Class_B : public Class_A
Class_C : public Class_B
Class_A
contains a constructor:
public: Class_A(const char *name, int kind);
Class_B
does not contain that constructor.
In Class_C
I wish to invoke the constructor of Class_A. Something like:Class_C(const char *name, int kind) : Class_A::Class_A(name,kind) {
}
The problem is that I cannot add an intermediate constructor to Class_B
, because Class_B
is generated code that regenerates every time I make clean. So I cannot make any lasting changes to Class_B
. Needless to say, the above line of the constructor in Class_C
gives the error: "type 'Class_A' is not a direct base of '
Class_C'".
Is there a way that I may invoke the constructor of Class_A
in the subclass Class_C
, without requiring the same type of constructor in Class_B
?
If you can't change the code that generates B
, then you are out of luck, AFAIK. But if the A
class contains such a constructor, maybe you can get away with adding a simple member function that sets those two variables and call it from inside the C
constructor? May not be as efficient as it gets, but atleast it works.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With