Calling the base class constructor from the derived class constructor

The constructor of PetStore will call a constructor of Farm; there’s
no way you can prevent it. If you do nothing (as you’ve done), it will
call the default constructor (Farm()); if you need to pass arguments,
you’ll have to specify the base class in the initializer list:

PetStore::PetStore()
    : Farm( neededArgument )
    , idF( 0 )
{
}

(Similarly, the constructor of PetStore will initialize
sizeF, by calling the constructor of Farm. The constructor of a class always calls the constructors of
all of its base classes and all of its members.)

Leave a Comment