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

Overloading and Operator Overloading Respectively.

C++ allows functions and operators to have the same name but different parameters through function and operator overloading. When an overloaded function or operator is called, the compiler selects the most appropriate definition based on the argument types provided. This process of selecting the best match is called overload resolution.

Uploaded by

Pallab Datta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
49 views

Overloading and Operator Overloading Respectively.

C++ allows functions and operators to have the same name but different parameters through function and operator overloading. When an overloaded function or operator is called, the compiler selects the most appropriate definition based on the argument types provided. This process of selecting the best match is called overload resolution.

Uploaded by

Pallab Datta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

C++ allows you to specify more than one definition for a function name

or an operator in the same scope, which is called function


overloading and operator overloading respectively.

An overloaded declaration is a declaration that is declared with the same


name as a previously declared declaration in the same scope, except that
both declarations have different arguments and obviously different
definition (implementation).

When you call an overloaded function or operator, the compiler


determines the most appropriate definition to use, by comparing the
argument types you have used to call the function or operator with the
parameter types specified in the definitions. The process of selecting the
most appropriate overloaded function or operator is called overload
resolution.

#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