Probléma:
throw exception("hibaüzenet"); g++ alatt nem működik (VS-ben igen).
error: no matching function for call to 'std::exception::exception(const char [])'
note: candidates are:
note: std::exception::exception()
note: candidate expects 0 arguments, 1 provided
note: constexpr std::exception::exception(const std::exception&)
note: no known conversion for argument 1 from 'const char []' to 'const std::exception&
Megoldás:
class myexception : public exception
{
public:
myexception(const string& msg) : m_msg(msg) { }
const char* what() const throw () { return m_msg.c_str(); }
~myexception() throw () { }
private:
string m_msg;
};
try {
throw myexception("hibaüzenet");
}
catch (exception& e) {
cerr << e.what();
}