Error - "throws different exceptions" in C ++

I get an error

error: declaration of 'virtual FXHost::~FXHost()' throws different exceptions error: than previous declaration 'virtual FXHost::~FXHost() throw ()' 

I am not sure how to start this decision, I have never come across this before.

in my .h I have:

 public: virtual ~FXHost() throw(); 

in my .cpp I have:

 FXHost::~FXHost() { gHost = NULL; } 

Pointers appreciated.

+4
source share
3 answers

throw() at the end of a function declaration is an exception specification. This means that the function never throws an exception. This cannot be overridden (only limited further) in derived classes, hence an error.

Since your implementation does not throw exceptions, all you need to do is add throw() to the destructor declaration.

See here why you should (not) use this (incorrect) C ++ function

+5
source
 FXHost::~FXHost() throw() { gHost = NULL; } 

Your implementation should be at least restrictive in terms of throwing exceptions as its declaration.

+3
source

Do you want to:

 FXHost::~FXHost() throw() { gHost = NULL; } 

Although this destructor offers poor design, it is unlikely that the destructor will work correctly by pointing a pointer, even a global pointer, to NULL.

+2
source

All Articles