An important objective of operator overloading is to make the code clearer and logical for the users of a class. Operator overloading facilitates passing of different parameters to the same function and getting different outputs with the different parameters. Let's understand this with the help of the following code snippet:
class B
{
public:
Int& operator[] (unsigned d); // many programers avoid using this syntax
};
Inline;
Int& B::operator[] (unsigned d) //This syntax is also avoid by some programmers
{
}
int main()
{
B abc;
abc[4] = 5; // This code os more clear and can easily understood by the user
}
}
In the preceding code snippet, the B class is declared with abc as an object. The abc object calls an array of 4 numbers.
class B
{
public:
Int& operator[] (unsigned d); // many programers avoid using this syntax
};
Inline;
Int& B::operator[] (unsigned d) //This syntax is also avoid by some programmers
{
}
int main()
{
B abc;
abc[4] = 5; // This code os more clear and can easily understood by the user
}
}
In the preceding code snippet, the B class is declared with abc as an object. The abc object calls an array of 4 numbers.
No comments:
Post a Comment