Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Constructor and Destructor Inheritance

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

like image 968
nitin_cherian Avatar asked Nov 12 '11 10:11

nitin_cherian


1 Answers

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.

like image 89
celtschk Avatar answered Oct 04 '22 07:10

celtschk