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
Write a note on encapsulation?
What are the problems faced by the developer using object oriented programming language?
How to make a class accessible as a web service?
What is hybrid inheritance?
What are all the operators that cannot be overloaded?
What is the function of pure virtual functions?
What is meant by overloading functions and operators?
What is a subclass?
How can we restrict inheritance for a class so that no class can be inherited from it?
How does abstraction differ from encapsulation.
What is dynamic or run time polymorphism?
What is the difference between an error and an exception?
Differentiate between an abstract class and an interface?
What is Overloading ? Is it similar to overriding ?
Explain what is meant by polymorphism?