I have a base class ‘A’ which has a subclass ‘B’ which has a subclass ‘C’ which has a subclass ‘D’.
I want D to call ‘A’s constructor,
D(int x,int y):A(x,y){};
but I am getting the error message:
error C2614: ‘D’ : illegal member initialization: ‘A’ is not a base or member.
D can call any of ‘C’s constructors fine but that is not what I want.
Any help would be super appreciated.
As Mark Ransom’s answer states, a derived class is only allowed to call its base class’ constructor.
In your case, you can solve the problem by passing along the constructor arguments to
Ddown the inheritance hierarchy untilA‘s constructor is called byBwith those arguments.Another option is to create a
protectedfunction, sayA::init( args )that can be called byDdirectly.