C++ 错误-“;抛出不同的异常”;在C++;
我得到一个错误,告诉我C++ 错误-“;抛出不同的异常”;在C++;,c++,exception-handling,C++,Exception Handling,我得到一个错误,告诉我 error: declaration of 'virtual FXHost::~FXHost()' throws different exceptions error: than previous declaration 'virtual FXHost::~FXHost() throw ()' 我不知道如何开始解决这个问题,我以前从未遇到过这个问题 在我的.h中,我有: public: virtual ~FXHos
error: declaration of 'virtual FXHost::~FXHost()' throws different exceptions
error: than previous declaration 'virtual FXHost::~FXHost() throw ()'
我不知道如何开始解决这个问题,我以前从未遇到过这个问题
在我的.h中,我有:
public:
virtual ~FXHost() throw();
在我的.cpp中,我有:
FXHost::~FXHost()
{
gHost = NULL;
}
非常感谢指针。函数声明末尾的throw()
是一个异常规范。这意味着函数从不抛出异常。这不能在派生类中重写(仅进一步限制),因此会出现错误
由于您的实现本身不会抛出异常,所以只需将throw()
添加到析构函数声明中即可
您想要:
FXHost::~FXHost() throw()
{
gHost = NULL;
}
尽管这个析构函数暗示了一个糟糕的设计——仅仅通过将指针(甚至是全局指针)设置为NULL,析构函数不太可能正常工作
FXHost::~FXHost() throw()
{
gHost = NULL;
}
您的实现在异常抛出方面必须至少与其声明一样严格。不要从析构函数抛出异常!你的头声明函数没有抛出异常,但是你的定义没有t@nos我想这就是他想说的,他的throw()看起来像是重置静态,以便在旧的单件被销毁后可以替换。这没什么问题。所有真正的清理工作都可能在实现RAII的成员主题中。@Ben那么谁在破坏旧主题呢?还有“主题”?我的意思是键入“子对象”。