0

How to inherit a constructor?

hi there,can you please help me out with this concept with an example,thanks.

29th Mar 2017, 2:49 PM
Akshayarekha
Akshayarekha - avatar
3 Respostas
0
When a derived class inherits from a base class, then when you create an object of the derived class, the base class constructor is automatically called before the derived class constructor. To give an example: class A { public: A() { cout << "Calling A constructor\n"; } }; class B: public A { public: B() { cout << "Calling B constructor\n"; } }; int main() { B b_obj(); return 0; } This will output Calling A constructor Calling B constructor
29th Mar 2017, 6:24 PM
Michael
0
thanks for your valuable explanations :)
30th Mar 2017, 1:54 AM
Akshayarekha
Akshayarekha - avatar