I am using a template function and I am passing and I may be sending instances of a variety of classes to a string stream. What can I do to make sure this continues to work?
Let me be more specific where do I define the behavior for this? Is there some member that should be on each class being sent to the string stream, should I in some enhance or extend the existing String stream (I was thinking building a class that inherits from sstream and overloads the << operator to handle all the possible classes)?
I had trouble even finding documentation on this, so even links to more resources would be helpful.
It sounds to me like you want to make stream insertion operators. for a class you want to be able to output to a stream, define the free function:
So if we have
SomeClassType z;, and we dostd::cout << z(or any other output stream, like anfstreamorstringstream), the compiler will look for and find our function, and call it. That is,std::cout << zbecomesoperator<<(std::cout, z)and inside there you output what you need.