At this function i need to return a char* variable, before i return it, I print it and it prints well. what happened to the variable that makes the return variable wrong and why?
The function:
const char* NameErrorException::what() const throw()
{
std::string str = "NameErrorException: name \'";
str += _name;
str += "\' is not defimed";
std::cout << str.c_str()<< std::endl; //Prints good
return str.c_str();
}
The print code:
catch (std::exception& ex)
{
//Prints something like "▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌♀·┘v♦"
std::cout << ex.what() << std::endl;
}
(NameErrorException inheritor from exception)
Thank you!