Constructor and Destructor Inheritance

nitin_cherian picture nitin_cherian · Nov 12, 2011 · Viewed 10.1k times · Source

I believe Constructors and Destructors in base class cannot be inherited by derived classes of the base class. Is my understanding correct.

Answer

celtschk picture celtschk · Nov 12, 2011

Your understanding is correct. For example, if you have

class Base
{
  Base(int i) {}
};

class Derived: public Base {};

Derived d(3);

This will not compile because the Base constructor is not inherited. Note that default and copy constructor are created by the compiler if possible, and call the corresponding constructor of base classes, therefore for those constructors it looks as if those were inherited.