Re: When is virtual fn def in base cls required?

Discussion in 'C++' started by Josephine Schafer, Jun 25, 2003.

  1. "Dick Bridges" <> wrote in message
    news:3ef87b65$...
    > I'm having a "senior moment". Can someone point me to a reference that
    > describes the circumstances requiring a base class to provide an
    > implementation for a pure virtual member function?
    >
    > TIA
    >
    >
    >
    > Posted Via Usenet.com Premium Usenet Newsgroup Services
    > ----------------------------------------------------------
    > ** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
    > ----------------------------------------------------------
    > http://www.usenet.com


    1 situation I can think of is when many derived classes have the same common
    behavior for some function
    but some derived classes have a different one.

    Say

    class Base{
    public:
    virtual void foo () = 0;
    ....
    };

    void Base::foo ()
    {
    // Some common implementaion
    }

    class Derived1: public Base{
    public:
    virtual void foo ();
    ...
    };


    void Derived1::foo (){
    //Some different implementation

    }

    class Derived2: public Base{
    public:
    virtual void foo ();
    ...
    };

    void Derived2::foo (){
    // Same as base class
    Base::foo ();
    }
    Josephine Schafer, Jun 25, 2003
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jiong Feng
    Replies:
    0
    Views:
    819
    Jiong Feng
    Nov 19, 2003
  2. Victor Bazarov
    Replies:
    0
    Views:
    725
    Victor Bazarov
    Jun 24, 2003
  3. Norbert Riedlin
    Replies:
    0
    Views:
    810
    Norbert Riedlin
    Jun 25, 2003
  4. J Peyret
    Replies:
    10
    Views:
    436
    Steven D'Aprano
    Mar 19, 2011
  5. Sean Ross
    Replies:
    3
    Views:
    122
    Aredridel
    Dec 25, 2003
Loading...

Share This Page