Unexpected Inheritance Output
For some reason, this code outputs the constructor and destructor multiple times. Does anybody know why? Is it once for each derived class? #include <iostream> using namespace std; class Mother { public: Mother() { cout << "Mother ctor" << endl; }; void sayHi() { cout << "Hi"; } void sayHello() { cout << "Hello"; } ~Mother() { cout << "Mother dtor" << endl; } }; class Daughter: public Mother { public: Daughter() {}; }; class Son: public Mother { public: Son() {}; }; int main() { Mother m; Daughter d; Son s; d.sayHi(); cout << "\n"; s.sayHello(); cout << "\n"; }