In C++, if a derived class redefines base class member method then all the base class methods with same name become hidden in derived class.
For example, the following program doesn’t compile. In the following program, Derived redefines Base’s method fun() and this makes fun(int i) hidden.
Even if the signature of the derived class method is different, all the overloaded methods in base class become hidden. For example, in the following program, Derived::fun(char ) makes both Base::fun() and Base::fun(int ) hidden.
Note that the above facts are true for both static and nonstatic methods.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- What are the operators that can be and cannot be overloaded in C++?
- Functions that cannot be overloaded in C++
- Can main() be overloaded in C++?
- Difference between Base class and Derived class in C++
- Publicly inherit a base class but making some of public method as private
- Virtual base class in C++
- Can we access global variable if there is a local variable with same name?
- Implementation of all Partition Allocation Methods in Memory Management
- How to convert a class to another class type in C++?
- Catching base and derived classes as exceptions
- Name Mangling and extern "C" in C++
- Quick way to check if all the characters of a string are same
- What all is inherited from parent class in C++?
- Different methods to reverse a string in C/C++
- 5 Different methods to find length of a string in C++
- Different methods to copy in C++ STL | std::copy(), copy_n(), copy_if(), copy_backward()
- Calling virtual methods in constructor/destructor in C++
- C++: Methods of code shortening in competitive programming
- Methods to concatenate string in C/C++ with Examples
- Default Methods in C++ with Examples