

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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 Questions & Answers
- What is the base class for all exceptions in C#?
- Virtual base class in C++
- Use overloaded methods to print array of different types in Java
- Math class methods in C#
- What is the base class for all data types in C#.NET?
- Base Overloading Methods in Python
- What is a base class in C#?
- Methods of StringBuffer class in Java.
- Methods of StringBuilder class in Java.
- Methods of StringTokenizer class in Java.
- What is a virtual base class in C++?
- Overloaded method and ambiguity in C#
- What are overloaded indexers in C#?
- Can main() be overloaded in C++?
- What is Regex class and its class methods in C#?
Advertisements