Can overriding be controlled ?

Discussion in 'C++' started by Vajira, Jan 19, 2005.

  1. Vajira

    Vajira Guest

    Lets say there is a inheritance heirarchy like this. C3 inherit from C2
    and C2 inherit from C1 ( C3 -> C2 -> C1 ). If C1 class has a public
    virtual member function call 'Remove()', can I limit overriding this
    member in C3 class ?
     
    Vajira, Jan 19, 2005
    #1
    1. Advertising

  2. * Vajira:
    > Lets say there is a inheritance heirarchy like this. C3 inherit from C2
    > and C2 inherit from C1 ( C3 -> C2 -> C1 ). If C1 class has a public
    > virtual member function call 'Remove()', can I limit overriding this
    > member in C3 class ?


    I assume you mean whether you can do something in C2 such that C3
    can be defined but cannot override the C1 member function.

    In that case the answer is, AFAIK, no.

    However, if you control the C1 implementation then you can add a dummy
    argument of a private type. Then the function can only be overridden
    by classes with access to that type. This does not, however, prevent
    derived classes from offering a same-named function.

    --
    A: Because it messes up the order in which people normally read text.
    Q: Why is it such a bad thing?
    A: Top-posting.
    Q: What is the most annoying thing on usenet and in e-mail?
     
    Alf P. Steinbach, Jan 19, 2005
    #2
    1. Advertising

  3. Vajira

    Vajira Guest

    Thank you, This is a nice idea.
    Anyway, Isn't it nice to have a keyword like 'final' in Java for C++?
     
    Vajira, Jan 21, 2005
    #3
  4. Vajira

    Attila Feher Guest

    Vajira wrote:
    > Thank you, This is a nice idea.
    > Anyway, Isn't it nice to have a keyword like 'final' in Java for C++?


    I see this request popping up many times, but I have never seen anyone
    telling a good enough reason for it. I do not recall needing it ever. Of
    course I don't mean it is not needed, just that I don't know if it would be
    worth the trouble.

    --
    Attila aka WW
     
    Attila Feher, Jan 27, 2005
    #4
    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. kevin bailey
    Replies:
    1
    Views:
    496
    bruce barker
    Nov 24, 2004
  2. Michael N. Christoff

    Mars Rover Controlled By Java

    Michael N. Christoff, Jan 16, 2004, in forum: Java
    Replies:
    146
    Views:
    6,299
    Greg Gauthier
    Jan 5, 2005
  3. Antoine Diot
    Replies:
    4
    Views:
    5,078
    pravda
    Jun 5, 2004
  4. PC Leung
    Replies:
    10
    Views:
    10,189
    PC Leung
    Jul 22, 2004
  5. jm
    Replies:
    0
    Views:
    279
Loading...

Share This Page