+ 1

BASE CLASS CONSTRUCTORS AND DESTRUCTORS ARE NOT INHERITED TO DERVIED CLASS ..THEN HOW THIS ...

include <iostream> using namespace std; class Mother { public: Mother() { cout <<"Mother ctor\n"; } ~Mother() { cout <<"Mother dtor\n"; } }; class Son: public Mother { public : Son(){cout<<"Son Ctor\n";} ~Son(){cout<<"Son Dtor\n";} }; int main() { Mother m; Son S; } /* Output: Mother Ctor Mother Dtor Son Ctor Son Dtor Mother Ctor Mother Dtor Constru,destruc also inherited from base class

6th Nov 2017, 4:47 PM
I'm_Groot
I'm_Groot - avatar
2 Answers
+ 4
The base class' constructor and destructor are not inherited, they are implicitly called by the derived class' constructor and destructor, respectively.
6th Nov 2017, 5:13 PM
Dennis
Dennis - avatar