What is the use of Operator Overloading?
Answer / ben jacob
Operator Overloading helps users/developers use a particular
class in an intuitive manner for different kind of
operations logically possible on the class.
It's used for ease of code read and maintainability.
e.g. Date 'b' can be subtracted from another instance of
Date, say 'a', to get the difference in number of days
between the two days.
So, you would overload the subtraction operator '-' for the
Date class accordingly.
Date a("07/04/2008);
Date b("05/04/2008);
//operator overoading for '-' for Date
//returns number of days
int Date::operator-(const Date& rhsDate)
{
//wotever logic
return <number of days between the (this) date and rhsDate>
}
| Is This Answer Correct ? | 5 Yes | 0 No |
What is the difference between abstract & interface?
Explain persistence?
What is the difference between aggregation and composition?
Why are virtual users created?
Why does the function arguments are called as "signatures"?
what are the main underlying concepts of object orientation?
What are virtual functions, base class pointer, derived class pointer, biding references?
0 Answers HPCL, Hughes Systique Corporation,
What is the function of messaging metaphor?
Which keyword can be used for overloading?
What are the features that are provided to make a program modular?
What is Overloading ? Is it similar to overriding ?
If a method definition has been specified in class , its base class , and the interface which the class is implementing, which definition will be picked if we try to access it using interface reference and class object?