0% found this document useful (0 votes)
38 views

Function Overloading in C++

This C++ program defines a printData class with three print methods that can handle different data types as arguments - an integer, float, and character pointer. The main function creates a printData object and calls each print method to output the passed in values of different types to the console.
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views

Function Overloading in C++

This C++ program defines a printData class with three print methods that can handle different data types as arguments - an integer, float, and character pointer. The main function creates a printData object and calls each print method to output the passed in values of different types to the console.
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

#include <iostream>

using namespace std;

class printData {
public:
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;
}
};

int main(void) {
printData pd;

// Call print to print integer


pd.print(5);

// Call print to print float


pd.print(500.263);

// Call print to print character


pd.print("Hello C++");

return 0;
}

You might also like