Please forgive my C++ naiveté
I was thinking of creating Exception classes that would inherit from std::stringstream so that I could use stringstream’s operator << to build up text error messages while at the same time being able to try catch the exceptions by type.
My code is something like
class ExceptionXYZ : public std::stringstream
{};
Void someFunction()
{
try
{
//do something
}
catch(const ExceptionXYZ& e)
{
//handle XYZ
}
Unfortunately my VS2008 compiler doesn’t like this and complains that
error C2248: 'std::basic_ios<_Elem,_Traits>::basic_ios' : cannot access private member declared in class 'std::basic_ios<_Elem,_Traits>'
basic_ios is a great grandparent (or thereabouts) of stringstream and there must be some implicit access violation somewhere, but between my extremely rusty C++ and the compiler’s unhelpful error message (it doesn’t tell me what private member it’s worried about) I’m a bit lost.
I imagine people do this kind of thing all the time (i.e. throw exceptions with text that have to be caught by type).
Help would be greatly appreciated