Are destructors overloadable?

痞子三分冷 提交于 2019-11-28 02:48:47

问题


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



来源:https://stackoverflow.com/questions/6243605/are-destructors-overloadable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!