Thread: virtual funtions

  1. #1
    Registered User
    Join Date
    Nov 2002

    virtual funtions

    if you redefine a virtual function does your redefine code get added to the original function or does it replace it?

  2. #2
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    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 :-

  3. #3
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Visalia, CA, USA
    It is possible to call a base classes function though. Also you should know that when you do something like this.

    class base {
        base() { whatever(); }
        virtual ~base() { }
        virtual void whatever() { 
             cout << "hello world";
    class child : public base {
        child() : base() { } //this is done by default
        virtual ~child() { }
        virtual void whatever() {
            cout << "something";
    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().

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Virtual Box
    By ssharish2005 in forum Tech Board
    Replies: 3
    Last Post: 02-12-2009, 05:08 AM
  2. Replies: 48
    Last Post: 09-26-2008, 03:45 AM
  3. Program with Shapes using Virtual Functions
    By goron350 in forum C++ Programming
    Replies: 12
    Last Post: 07-17-2005, 01:42 PM
  4. C++ XML Class
    By edwardtisdale in forum C++ Programming
    Replies: 0
    Last Post: 12-10-2001, 11:14 PM
  5. Exporting Object Hierarchies from a DLL
    By andy668 in forum C++ Programming
    Replies: 0
    Last Post: 10-20-2001, 01:26 PM