views:

61

answers:

1

Suppose I have some class C, and I inherit from it and name this class D. Do I always have to call C's default constructor as in this example:

class C {
    public:
        C() { ... }
};

class D {
    public:
        D() : C() { ... }
};

Note that C has only the default constructor. Do I have to call it from D? I couldn't figure out how to find this out.

Thanks, Boda Cydo.

+5  A: 

You don't need to specify the base class constructor in your derived type constructor's initializer list. When it is omitted an attempt will be made to call the base constructor with no parameters. If no such parameterless base constructor exists, then you'll get a compiling error.

Brian R. Bondy
Thank you for the answer!
bodacydo