Function Overloading  in C++

  • You can have multiple definitions for the same function name in the same scope.
  • The definition of the function must differ from each other by the types and/or the number of arguments in the argument list.
  • You cannot overload function declarations that differ only by return type.


#include <iostream>

class printData
 void print(int i) {
 cout << "Printing int: " << i << endl;
 void print(double f) {
 cout << "Printing float: " << f << endl;
void print(char* c) {
 cout << "Printing character: " << c << endl;

void main(void)
 printData pd;
 // Call print to print integer
 // Call print to print float
 // Call print to print character
 pd.print("Hello C++");


Printing int: 9
Printing float: 100.200
Printing character: Hello C++


Subscribe us on Youtube

Share This Page on

Ask Question