concepts of overloding operators with an example
oops
Collapse
X
-
Tags: None
-
Use the Internet to research this.
The idea is to make yout code easy to use. If you have x + 10 and x is an int then 10 is added to the int value. If x is a date, then 10 days would be added to the date value.
Unfortunately, the + does not work with dates. So, the overload is your implementation of the + operator for use with date variables.
Truly, the Internet has a ton of info on this. -
Hi,
Assume that you wants to add two strings (concatenate) say S1 and S2 like below
S = S1 + S2
But its not possible since + doesn't add strings, So you need to overload + operator to add (concatenate) the strings.
This is just an example to understand when you need to overload operators.
Thanks,
ManjunathComment
Comment