Click here to hide categories Click here to show left categories

User: Home          welcome : Guest          Log In / Register here     




Operator Overloading

From the word overloading we mean that to give some new meaning to a thing. In this process the old meaning of the thing is not changed.

Thus in the process of overloading we can give new meaning to the existing operators. The existing operators like +, - etc are made to be used for the predefined data types like int, float etc. But they are not made to operate on objects. We will have to overload them so that they can be used with the objects in the same way as they are used with predefined data types. Thus the original meaning of the operators is that they are made to be used with predefined data types but by overloading them we can make them work with objects and thus we are giving them a new meaning.

There are certain operators that can not be overloaded. These are:

1. Class member access operators- ., .* .
2. Scope Resolution Operator- ::
3. Sizeof operator: sizeof
4. Conditional Operator: ?:

For overloading the operators a special function is used. This function is called ‘Operator Function’. It can be the member function of the class or the friend function. The number of arguments to be passed to this function depends on two things- 1. Function is member function of the class or friend function 2. The operator to be overloaded is unary operator or binary operator.

For overloading the operators a special function is used. This function is called ‘Operator Function’. It can be the member function of the class or the friend function. The number of arguments to be passed to this function depends on two things- 1. Function is member function of the class or friend function 2. The operator to be overloaded is unary operator or binary operator.

Operator overloading using member function

Operator overloading using friend function

Share this article   |    Print    |    Article read by 2863 times
Author:
Rohit kakria
I am software developer, moderator of xpode.com
Related Articles:
Related Interview Questions: No related interview question