Are destructors overloadable?

2019-01-26 05:29发布

enable_if doc page says:

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

Are destructors overloadable?

2条回答
Ridiculous、
2楼-- · 2019-01-26 05:59

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()’

查看更多
聊天终结者
3楼-- · 2019-01-26 06:00

No


      

查看更多
登录 后发表回答