Answer Posted / 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 |
Post New Answer View All Answers
What is difference between encapsulation and abstraction?
What is the difference between function overloading and over riding?
How many instances can be created for an abstract class?
What is the difference between data hiding and implementation?
What interface must an object implement before it can be written to a stream as an object?
What is the abstract method modifier?
Can encapsulation be called as a security device?
What are the major differences between late and dynamic binding?
Can I implement polymorphism using abstract class?
What is the use of ‘finalize’?
What is single and multiple inheritance?
What's the benefit of using inheritance?
Differentiate between data abstraction and encapsulation.
What is the use of destructive method?
Why we use oops concepts? What is its advantage?