operator overloading means giving capibility to the operator to work on different types of operands.
The operator + , -, * etc. work on operands of type int, float, etc. we can overload those operators by giving them the capability to work on user defined data types.
For example , to add two structure variables of type data we can write the following
struct data
{
int i;
float t;
}
data c, a = {1, 2.5f}, b = {3.5, 5f};
c = a +b;
instead of
c.i = a.i + b.i;
c.i = a.f + b.f;
In a+b , the ' +' operator is overlaoded to add two structure variables
we would of course have to provide the overloaded operator + function to carry out the addition;

0 comments:
Post a Comment