Function overloading

Function overloading:

In function overloading we have multiple definitions for the same function name in the same scope. The declaration of the function must differ from each other by the types and/or the number of arguments in the argument list. we can’t overload function declarations that differ only by return type.

Example
#include<iostream.h>

class printData

{

public: void show(int i)

{

cout << “Display int: ” << i << endl;

}

void show(double ff)

{

cout << ” Display float value: ” << ff<< endl;

}

void show(char* cc)

{

cout << ” Display character: ” << cc << endl;

}

};

int main(void)

{

printData pd1; // Call print to print integer

Pd1.show(8); // Call print to print float

Pd1.show(500.46); // Call print to print character Pd1.show(“Welcome to C++”);

return 0;

}

Output
Display int:8

Display float value:500.46

Display character:Welcome to c++

 

Leave a Reply

Your email address will not be published. Required fields are marked *