if you redefine a virtual function does your redefine code get added to the original function or does it replace it?
This is a discussion on virtual funtions within the C++ Programming forums, part of the General Programming Boards category; if you redefine a virtual function does your redefine code get added to the original function or does it replace ...
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.
Free the weed!! Class B to class C is not good enough!!
And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi
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"; } };