redefining and overriding members

This is a discussion on redefining and overriding members within the C++ Programming forums, part of the General Programming Boards category; I have a question about inheritance. When you REDEFINE a base class member function in a derived class, the function ...

  1. #1
    Registered User
    Join Date
    Nov 2001
    Posts
    13

    redefining and overriding members

    I have a question about inheritance.

    When you REDEFINE a base class member function
    in a derived class, the function signatures DO NOT have to match.

    When you OVERRIDE a base class member function
    in a derived class, the function signatures MUST match.

    What is the difference between REDEFINING and OVERRIDING ?

  2. #2
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    As far as I understand it;

    Say base class has member func print()

    From the perspective of the scope of the derived class:

    OVERRIDING print()- The derived class has 1 print function that is detailed by the derived class

    REDEFINING print()- The derived class has 2 print functions, 1 detailed by the derived class, 1 detailed by the base class.

  3. #3
    Registered User
    Join Date
    Nov 2001
    Posts
    13
    if I define a member in the BASE class:
    ----------------------
    void print() const
    ----------------------

    AND OVERRIDE it in the DERIVED class:
    ----------------------
    void print() const // signature must be the same
    ----------------------

    OR REDEFINE it in the DERIVED class:
    -------------------------
    void print(int) const // signature can be different
    -------------------------

    I have to explicitly qualify the BASE to call the BASE member
    in both situations:
    ---------------------------
    DERIVED object1;

    object1.BASE::print();
    ---------------------------

    My assumption was that OVERRIDING "hides" the BASE member
    and that REDEFINING just overloads the member.

    so what is the difference between OVERRIDING and REDEFINING ?
    Last edited by strobe9; 01-09-2002 at 01:46 PM.

  4. #4
    S­énior Member
    Join Date
    Jan 2002
    Posts
    982
    You can't overload using inheritance, as soon as you specify a function of the same name in a derived class you are overriding the base version regardless of the arguments it takes. The derived class function name hides the base class function. If you try to call the base class function without the scope resolution operator, the compiler will think you are trying to call the derived class function and generate an error if the syntax isn't correct.

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21