Are destructors overloadable?

2019-01-26 05:16发布

问题:

enable_if doc page says:

Constructors and destructors do not have a return type; an extra argument is the only option.

Are destructors overloadable?

回答1:

No


      



回答2:

Are destructors overloadable?

The answer is plain No.
Two versions of desturctor cannot co-exist in a class body.

However unlike the popular belief, note that destructor does have 2 syntax.

struct E {
  ~E();  // syntax-1
  ~E() throw(); // syntax-2
};

Syntax-2 is less popular. But it is mandatory, if the base class destructor contains similar syntax. The best example is inheriting std::exception.

Note that, not complying to such syntax results in:

error: looser throw specifier for ‘virtual E::~E()’