There are certain situation when we want to make some of the public base class functions as private in the derived class. Suppose both base and child class has getter and setter methods
i = 4 j = 2 k = 3
Here if we need to restrict the call of function “setBaseProperties” and “showBaseProperties” with Child class object “c”. This can be achieved without overriding the function as below:
We re-declare base class functions in derived class scope using “using” syntax. We do it in private section of derived class.
i = 1 j = 2 k = 3
Rated as one of the most sought after skills in the industry, own the basics of coding with our C++ STL Course and master the very concepts by intense problem-solving.
- How to access private/protected method outside a class in C++
- Difference between Base class and Derived class in C++
- Can we access private data members of a class without using a member or a friend function?
- Virtual base class in C++
- Hiding of all overloaded methods with same name in base class
- Code valid in both C and C++ but produce different output
- Private Destructor
- Can a constructor be private in C++ ?
- Difference between Private and Protected in C++ with Example
- Can virtual functions be private in C++?
- C/C++ Ternary Operator - Some Interesting Observations
- Some Interesting facts about default arguments in C++
- List in C++ | Set 2 (Some Useful Functions)
- Some useful C++ tricks for beginners in Competitive Programming
- Some interesting facts about static member functions in C++
- Decision Making in C / C++ (if , if..else, Nested if, if-else-if )
- Catching base and derived classes as exceptions
- How to convert a class to another class type in C++?
- What happens when more restrictive access is given to a derived class method in C++?
- What all is inherited from parent class in C++?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.