-
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 ?
-
&TH of undefined behavior
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.
-
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 02:46 PM.
-
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