Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Borland C++ 2.x ( with Turbo C ) - <b>virtual virtual function modifier</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 virtual                 Virtual Function Modifier

            The virtual modifier is used to ease the way for inheritance
    procedures. You can have either virtual base classes or virtual
    functions.
            A virtual base class lets you specify a base class more than
    once in a derived class -- if done indirectly. For example, this is
    illegal because a base class can't be specified more than once in a
    derived class:

    class AAAA { ...};
    class BBBB : AAAA, AAAA {statements;};

    However, you can do this indirectly as follows:

    class BBBB : public AAAA { ... }
    class CCCC : public AAAA { ... }
    class DDDD : public BBBB, public CCCC { ... }  // OK

    If the compiler objects, add the virtual modifier to make the base
    classes virtual:

    class BBBB : virtual public AAAA { ... }
    class CCCC : virtual public AAAA { ... }
    class DDDD : public BBBB, public CCCC { ... }  // OK

            Virtual functions, on the other hand, let derived classes
    provide different versions of a base class function. The idea is to
    define a virtual function in a base class and then redefine it in a
    derived class. In this case, the virtual function finch_spotted() is
    redefined in the derived class my_birdwatch:

              class birdwatch {
                 int num_finches;
                 int num_seagulls;
              public:
                 int virtual finch_spotted();
                 int virtual seagull_spotted();
              };

              class my_birdwatch : public birdwatch {
                 int num_blue_jays;
                 int num_sparrows;
                 int finch_spotted();
              };

See Also: private protected public

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson