How to restrict overiding a function in derived class?

Discussion in 'C++' started by Pankh, Sep 16, 2004.

  1. Pankh

    Pankh Guest

    Hi,

    Is it possible to restrict overiding a function in derived class?
    To be more clear, I have base class with function foo() and I do not
    want any derived class to implement foo() again. Always base version
    of foo() should be called on any derived class object. Can I do that?

    Thanks.
    Pankh, Sep 16, 2004
    #1
    1. Advertising

  2. (Pankh) writes:

    > Hi,
    >
    > Is it possible to restrict overiding a function in derived class?
    > To be more clear, I have base class with function foo() and I do not
    > want any derived class to implement foo() again. Always base version
    > of foo() should be called on any derived class object. Can I do that?


    No, sorry. You have to write it into your documentation, that this
    method must not be overridden.

    Kind regards,
    Nicolas


    --
    | Nicolas Pavlidis | Elvis Presly: |\ |__ |
    | Student of SE & KM | "Into the goto" | \|__| |
    | | ICQ #320057056 | |
    |-------------------University of Technology, Graz----------------|
    Nicolas Pavlidis, Sep 16, 2004
    #2
    1. Advertising

  3. Pankh

    Tom Widmer Guest

    On 15 Sep 2004 20:29:01 -0700, (Pankh) wrote:

    >Hi,
    >
    >Is it possible to restrict overiding a function in derived class?
    >To be more clear, I have base class with function foo() and I do not
    >want any derived class to implement foo() again. Always base version
    >of foo() should be called on any derived class object. Can I do that?


    From your specific description, just make foo non-virtual.

    Tom
    Tom Widmer, Sep 17, 2004
    #3
    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. John Saunders

    Overiding Page Class

    John Saunders, Aug 26, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    352
    Vincent V
    Aug 27, 2003
  2. Danny Anderson
    Replies:
    1
    Views:
    1,327
    David Dorward
    Sep 10, 2003
  3. Ronnie
    Replies:
    4
    Views:
    420
    Ronnie
    Nov 19, 2003
  4. Replies:
    1
    Views:
    387
    myork
    May 23, 2007
  5. Replies:
    1
    Views:
    374
    Victor Bazarov
    May 23, 2007
Loading...

Share This Page