
- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
Hiding of all overloaded methods in base class in C++
In C++, we can use the function overloading techniques. But if some base class has one method in overloaded form (different function signature with the same name), and the derived class redefines one of the function which is present inside the base, then all of the overloaded version of that function will be hidden from the derived class.
Let us see one example to get the clear idea.
Example
#include <iostream> using namespace std; class MyBaseClass { public: void my_function() { cout << "This is my_function. This is taking no arguments" << endl; } void my_function(int x) { cout << "This is my_function. This is taking one argument x" << endl; } }; class MyDerivedClass : public MyBaseClass { public: void my_function() { cout << "This is my_function. From derived class, This is taking no arguments" << endl; } }; main() { MyDerivedClass ob; ob.my_function(10); }
Output
[Error] no matching function for call to 'MyDerivedClass::my_function(int)' [Note] candidate is: [Note] void MyDerivedClass::my_function() [Note] candidate expects 0 arguments, 1 provided
- Related Articles
- Use overloaded methods to print array of different types in Java
- Golang program to show data hiding in class
- What is the base class for all exceptions in C#?
- Base Overloading Methods in Python
- Methods of StringBuffer class in Java.
- Methods of StringBuilder class in Java.
- Methods of StringTokenizer class in Java.
- How to get a list of all the test methods in a TestNG class?
- What is the base class for all data types in C#.NET?
- Useful Methods of Integer Class in Ruby
- BitSet class methods in Java
- Math class methods in C#
- Defining Class Methods in Perl
- Range class methods in Ruby
- Explain Class Methods in Coffeescript

Advertisements