Background
I have a container class which uses vector
The operator overloading in this case is not good practice as it makes the code less readable. The standard std::vector
doesn't have it either for pushing elements, for good reasons.
If you're worried about the caller code being too long, you could consider this instead of the overloaded operator:
container.AddChar("First").AddChar("Second");
This will be possible if you have AddChar()
return *this
.
It's funny that you have this toString()
function. In that case, an operator<<
to output to a stream would be the standard thing to use instead! So if you want to use operators make the toString()
function an operator<<
.