I was trying to use a constexpr inside an exception message, but this does not work: The followoing code is compiling well on g++ (using c++11 or c++14).
#include <exception>
constexpr auto TEST = "test";
class test_throw : public std::exception {
public:
virtual const char* what() const throw() {
return (std::string("THROW ")+TEST).c_str();
}
};
int main()
{
throw test_throw{};
}
I wonder why my exception is outputting an empty message, ok that seems like a bad trick, but I don't understand how the message can be empty.
Is there a way to achieve this without replacing the constexpr by a macro ?
Aucun commentaire:
Enregistrer un commentaire