I am trying to overload the what() method of the exception class which returns a const char*.
What's the best way to do it if I have a std::string on the stack, storing the string I want to return?
is not a good idea because mystr would be deallocated by the time the caller reads the string.Code:return mystr.c_str();
Allocating a buffer of the same size on the stack and copying the string to it will work, but isn't that leaky? ("delete e.what();" just looks... wrong to me)
What's the conventional way to go about doing this?