Javatpoint Logo

91-9990449935

 0120-4256464

Javatpoint Logo

C++ Overloading (Function and Operator)

If we create two or more members having same name but different in number or type of parameter, it is known as C++ overloading. In C++, we can overload:

  • methods,
  • constructors, and
  • indexed properties

It is because these members have parameters only.

Types of overloading in C++ are:

  • Function overloading
  • Operators overloading

C++ Function Overloading

Having two or more function with same name but different in parameters, is known as function overloading in C++.

The advantage of Function overloading is that it increases the readability of the program because you don't need to use different names for same action.

C++ Function Overloading Example

Let's see the simple example of function overloading where we are changing number of arguments of add() method.

Output:

30
55

C++ Operators Overloading

Operator overloading is used to overload or redefine most of the operators available in C++. It is used to perform operation on user define data type.

The advantage of Operators overloading is to perform different operations on the same operand.

C++ Operators Overloading Example

Let's see the simple example of operator overloading in C++. In this example, void operator ++ () operator function is defined (inside Test class).

Output:

The Count is: 10




Latest 4 Tutorials on JavaTpoint