Calling the base class constructor in C++

The default base class constructor will automatically be called by a derived class default constructor.
If you need to call another base class constructor, you need to put the call to it in the derived class initializer list:


class Base
{
public:
    Base(int i)
        i_(i)
    {
    }
private:
    int i_;
};

class Derived : public Base
{
public:
    Derived(int i, j)
        : Base(i), j_(j)
    {
    }
private:
    int j_;
};

See Typedef super for a handy idiom for referring to the base class.