class Base
{
public:
Base(){Foo();}
~Base(){Foo();}
virtual void Foo(){std::cout<<"base";}
};
class Derived: public Base
{
public:
Derived(){Foo();}
~Derived(){Foo();}
void Foo(){std::cout<<"derived";}
};
//main
{
Derived d;
}
Any idea why this code prints out "base" and "derived"?
I understand the advice is not to put virtual function calls inside constructor or desctructor, I just want to know why the above code would have the behaviour. Thanks
//main
), and if you think about it for awhile, you'll see why. – Sclar