+ 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
1 ответ
+ 4
The base class' constructor and destructor are not inherited, they are implicitly called by the derived class' constructor and destructor, respectively.