overloading operator+ as addition and using concatenation

hello,

I am creating an overloaded function that returns item containing
the parts of two complex numbers.

Originally, the function would add the two complex numbers as their separate parts, return them that way, and I would concatenate them together in my Print(). But this looks really messy; I wanted to use the overloaded function to return a concatenated string of the complex number as a solution.

Is this possible? I recieved errors before, because I would be concatenating with type Item, and the function would try to add them instead, even if I was concatenating with a string. If I assigned the Item type variables to a separate type ( string or float) and concatenated that way, would it work, or would it still throw errors?

Basically, my overall question is: can I concatenate a string within an operator+ overloaded function, when the function is for ADDITION.

DO NOT give me code or detailed design ideas; I mostly need to know if it's possible or if I'm wasting my time. This is a homework assignment

Thank you for your time :)
In C++ operator+ is normally not used to concatenate strings with other types. Instead we often use operator<< to write to streams. If you use std::ostringstream you can easily get the result as a string.
question is: can I concatenate a string within an operator+ overloaded function, when the function is for ADDITION.


Yes it's possible.
Peter87, could you tell me more about std::ostringstream?
Topic archived. No new replies allowed.