Operator Overloading in c++

Operator Overloading ?

The meaning of an operator is always same for variable of basic types like: int, float, double etc. For example: To add two integers, + operator is used.

In C++, we can make operators to work for user defined classes. This means C++ has the ability to provide the operators with a special meaning for a data type, this ability is known as operator overloading.

Syntax

 return_type class_name  : : operator op(argument_list)  
 {  
     // body of the function.  
 } 

Example 1:



Output :

 x = 20, y = 20
 x = 30, y = 0

Example 2:



Output :

 Count: 6