An object has a string and needs to be constructed.
#include <string>
class SDLException
{
private:
std::string what_str;
public:
SDLException(const std::string &msg);
~SDLException(void);
};
The string has a hidden dependency that i need to consider (SDL_GetError()
). I can construct the string in a function. But i do not know how to use a return value of that function to initialize a string member.
#include "SDLException.hpp"
#include <sstream>
#include <string>
#include <SDL.h>
static void buildSTR(const std::string &msg)
{
std::ostringstream stream;
stream << msg << " error: " << SDL_GetError();
std::string str = stream.str();
//if i return a string here it would be out of scope when i use it
}
SDLException::SDLException(const std::string &msg)
: what_str(/*i want to initialise this string here*/)
{}
SDLException::~SDLException(void){}
How can i initialize the member what_str
with a minimum amount of overhead?
The content of what_str
should be equal to the content of str
.