if you redefine a virtual function does your redefine code get added to the original function or does it replace it?
Printable View
if you redefine a virtual function does your redefine code get added to the original function or does it replace it?
it replaces it.
You basically call the function in the base class and the call actually gets dispatched to the same function but in the derived class as long as you use dynamic binding.
It is possible to call a base classes function though. Also you should know that when you do something like this.
The whatever() called in base's constructor will be base's whatever() even when a child is created. What I mean (that wasn't very clear) is that when a new child calls base's constructor during its own construction base::whatever() will be called NOT child::whatever().Code:class base {
public:
base() { whatever(); }
virtual ~base() { }
virtual void whatever() {
cout << "hello world";
}
};
class child : public base {
public:
child() : base() { } //this is done by default
virtual ~child() { }
virtual void whatever() {
cout << "something";
}
};