How can we use + operator in overloading?

Recommended Answers

The string class overloads the + operator to do string concatenation.
You seldom have to use operator overloading yourself.
You could use it, if you had for example written a date class or complex number class, to add two dates or complex numbers together.

Jump to Post

All 2 Replies

The string class overloads the + operator to do string concatenation.
You seldom have to use operator overloading yourself.
You could use it, if you had for example written a date class or complex number class, to add two dates or complex numbers together.

I up-voted ddanbe's post. That said, operator overloading can be very useful, especially output/input operators and such. As mentioned in ddanbe's post, date classes often overload the + operator. Example, adding a number of days to a date. IE, today + 7 = same-day-next-week.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.