please help me in distinguish redefining functions, overloading functions and overriding functions.

Discussion in 'C++' started by Xiangliang Meng, Jun 21, 2004.

  1. Hi, all.

    When reading C++ books, I'm alway confused by those terms "redefining
    functions", "overloading functions" and "overriding functions".

    Please give me some comments on those terms. Thanks.

    If giving more strategy hehind them, more helpful.

    Best Regards,

    Xiangliang Meng
    Xiangliang Meng, Jun 21, 2004
    #1
    1. Advertising

  2. "Xiangliang Meng" <> wrote...
    > When reading C++ books, I'm alway confused by those terms "redefining
    > functions", "overloading functions" and "overriding functions".
    >
    > Please give me some comments on those terms. Thanks.
    >
    > If giving more strategy hehind them, more helpful.


    Overloading is defining functions with the same name but with
    different arguments in the _same_scope_. For example, members
    of the same class would be overloaded if they have the same
    name but different arguments (even just 'const' after the
    function declaration counts):

    struct foo {
    void overloaded();
    void overloaded(int); // same scope
    };

    Redefining (correct term is "hiding") is declaring a function
    (and in fact, any symbol) with the same name in a more enclosed
    scope. For the consistency's sake, derived classes' scope is
    considered more enclosed than the base class' one.

    struct base {
    void somefunction();
    };

    struct derived : base {
    void somefunction(int); // hides base::somefunction
    };

    Overriding relates to _virtual_ function _only_. And it can
    happen if the function that overrides has the _same_ arguments:

    struct base {
    virtual void foo();
    };

    struct derived : base {
    void foo(); // overrides base::foo
    };

    struct derived2 : base {
    void foo(int); // does NOT override but instead _hides_
    };

    As to strategy, I am not sure what to tell you. Each of those
    language features has its uses. Practice.

    Victor
    Victor Bazarov, Jun 21, 2004
    #2
    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. KK
    Replies:
    2
    Views:
    545
    Big Brian
    Oct 14, 2003
  2. iceColdFire
    Replies:
    11
    Views:
    13,307
    Jaspreet
    May 18, 2005
  3. Replies:
    6
    Views:
    341
    Ron Natalie
    Jul 18, 2006
  4. yashwant pinge
    Replies:
    8
    Views:
    454
  5. andreyvul

    redefining functions

    andreyvul, Nov 24, 2008, in forum: C Programming
    Replies:
    16
    Views:
    1,491
    Nick Keighley
    Dec 1, 2008
Loading...

Share This Page