What does this error mean? How can I fix it? This is the header code that's causing it:
class BadJumbleException : public exception {
public:
BadJumbleException (const string& msg); // Constructor, accepts a string as the message
string& what(); // Returns the message string
private:
string message; // Stores the exception message
};
And this is the source code:
BadJumbleException::BadJumbleException (const string& m) : message(m) {}
string& BadJumbleException::what() { return message; }
EDIT: This is the error:
looser throw specifier for 'virtual BadJumbleException::~BadJumbleException()
In C++03, per §18.6.1/5, std::exception
has a destructor that is declared such that no exceptions can be thrown out of it (a compilation error will be caused instead).
The language requires that when you derive from such a type, your own destructor must have the same restriction:
virtual BadJumbleException::~BadJumbleException() throw() {}
// ^^^^^^^
This is because an overriding function may not have a looser throw specification.
In C++11, std::exception::~exception
is not marked throw()
(or noexcept
) explicitly in the library code, but all destructors are noexcept(true)
by default.
Since that rule would include your destructor and allow your program to compile, this leads me to conclude that you are not really compiling as C++11.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With