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 are the different types of inheritance?
What are all the languages which support oop?
What do you mean by virtual function and virtual classes?
What is the order of call of constructors in inheritiance?
Is it possible to create partial structs, interfaces and methods?
What is the @functionalinterface annotation?
What is abstraction? How does it differ from encapsulation
What is the use if instanceof keyword?
Explain what is object oriented programming language?
Does java support multiple inheritance? if not, what is the solution?
what is virtual function and pure virtual function ?
How can we restrict inheritance for a class so that no class can be inherited from it?
What is the function of pure virtual functions?
Explain persistence?
Classes and structs support inheritance. Is this statement true or false?