Operator overloading is the ability to tell the compiler how to perform a certain operation when its corresponding operator is used on one or more variables. Operator overloading is used to give special meaning to the commonly used operators (such as +, -, * etc.) with respect to a class. By overloading operators, programmer can control or define how an operator should operate on data with respect to a class. Operating overloading allow to pass different variable types to the same function and producing different results.
Operators are overloaded in c++ by creating operator functions either as a member or a Friend Function of a class. Operator overloading provides NO additional functionality to the code. It just compiles to normal function calls. It's even written out like normal function calls. It is mainly for aesthetics. There is, however, one extremely useful set of operators to overload that makes life much easier: the streaming operators.

          Operator overloading is the ability to tell the compiler how to perform a certain operation when its corresponding operator is used on one or more variables. For example, the compiler acts differently with regards to the subtraction operator “-“ depending on how the operator is being used. When it is placed on the left of a numeric value such as -48, the compiler considers the number a negative value. When used between two integral values, such as 80-712, the compiler applies the subtraction operation. When used between an integer and a double-precision number, such as 558-9.27, the compiler subtracts the left number from the right number; the operation produces a double-precision number. When the - symbol is doubled and placed on one side of a variable, such as --Variable or Variable--, the value of the variable needs to be decremented; in other words, the value 1 shall be subtracted from it. All of these operations work because the subtraction operator “-” has been reconfigured in various classes to act appropriately.

#include <iostream.h> 
  class myclass
  {
    int sub1, sub2;
  public:
        myclass(){}
    myclass(int x, int y){sub1=x;sub2=y;}
    myclass operator +(myclass);
    void show(){cout<<sub1<<endl<<sub2;}
  };
 
  myclass myclass::operator +(myclass ob)
  {
    myclass temp;
    temp.sub1=sub1 + ob.sub1;
    temp.sub2=sub2 + ob.sub2;
    return temp;
  }
 
  void main()
  {
    myclass ob1(10,90);
    myclass ob2(90,10);
    ob1=ob1+ob2;
    ob1.show();
  }

            To declare a binary operator function as a nonstatic member, declare it in the form:
ret-type operatorop( arg )
where ret-type is the return type, op is one of the operators listed in the preceding table, and arg is an argument of any type.
To declare a binary operator function as a global function, you must declare it in the form:
ret-type operatorop( arg1, arg2 )

where ret-type and op are as described for member operator functions and arg1 and arg2 are arguments. At least one of the arguments must be of class type