• Operator overloading

Operator overloading is compile time polymorphism.

The operator overloading provides mechanism to perform operations on user defined data type.

We can give special meaning to any operators in which program it is implemented.

Rules for operator overloading:

1.Only existing operator can be overloaded.

2.The overloaded operator must have at least one operand that is user defined type.

3.We cannot change the basic meaning and syntax of an operator.

4.We cannot use friend function to overload certain operators. However member function can be used to overload them.

5.Unary operators, overloaded by means of a member function, take no explicit argument s and return no explicit value, but, those overloaded by means of a friend function, take one reference argument.

6.Binary operators overloaded through a member function take one explicit argument and those which are overloaded through a friend function take two explicit arguments.

7.When using binary operators overloaded through a member function, the left hand operand must bean object of the relevant class.


class Complex
    int x,y;
        void getdata()
            cout<<" enter the real nad imaginary parts of a complex number: ";
        Complex operator +(Complex c)
            Complex c1;
            return c1;
        void disp()
void main()
    Complex c1,c2,c3;