0% found this document useful (0 votes)
3 views1 page

C++ Function Overloading Example

The document contains a C++ program that defines a class 'Temp' with overloaded 'add' methods. These methods demonstrate function overloading by differing in argument types and return types. The main function creates an instance of 'Temp' and calls the overloaded 'add' methods with various parameters.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views1 page

C++ Function Overloading Example

The document contains a C++ program that defines a class 'Temp' with overloaded 'add' methods. These methods demonstrate function overloading by differing in argument types and return types. The main function creates an instance of 'Temp' and calls the overloaded 'add' methods with various parameters.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

#include <iostream>

using namespace std;


class Temp
{
private:
int x = 10;
double x1 = 10.1;
public:
void add(int y)
{
cout << "Value of x + y is: " << x + y << endl;
}
// Differ in the type of argument.
void add(double d)
{
cout << "Value of x1 + d is: " << x1 + d << endl;
}
// Differ in the return type of function.
int add(int y, int z)
{
cout << "Value of x + y + z is: " << x + y + z << endl;
}

};
int main() {
Temp t1;
[Link](10);
[Link](11.1);
[Link](12,13);

return 0;
}

You might also like