Are destructors overloadable?

醉酒当歌 提交于 2019-11-29 09:24:20
Prasoon Saurav

No


      

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

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