A
Andrea Crotti
I have many classes where I overloaded operator<< to get an easier
output...
But now I'm in the situation that I want to get a string representing
the object, so it doesn't work very well.
Should I rewrite everything in the form
string toString() {
return string_representation;
}
and then print with
cout << obj.toString()
or is there an even smarter way (for example if "cout" would always call
"toString()" on the object if available)?
output...
But now I'm in the situation that I want to get a string representing
the object, so it doesn't work very well.
Should I rewrite everything in the form
string toString() {
return string_representation;
}
and then print with
cout << obj.toString()
or is there an even smarter way (for example if "cout" would always call
"toString()" on the object if available)?