Class inherited from class without default constructor

The constructor should look like this:

A(int i) : B(i) {}

The bit after the colon means, “initialize the B base class sub object of this object using its int constructor, with the value i”.

I guess that you didn’t provide an initializer for B, and hence by default the compiler attempts to initialize it with the non-existent no-args constructor.

Leave a Comment