Overrriding destructor of std:exception
The following program does not compile in g++ 4.4 if line 8 is commented.
Why? It seems that when I override std::exception constructor, I must
override its destructor as well. What's the reason for this?
#include<iostream>
#include<exception>
using namespace std;
class A : public exception {
public:
A(string msg) : _msg(msg) {}
//~A() throw(){}; // line 8
const char* what() const throw() { return _msg.c_str();}
private:
string _msg;
};
int main()
{
}
The compilation error is:
error: looser throw specifier for 'virtual A::~A()'
No comments:
Post a Comment