How do I get the member function pointer of a destructor?

[亡魂溺海] 提交于 2019-11-30 17:27:45

问题


Assume I have

struct X {
  ~X() {}
};

What's the type of and how do I get the member function pointer of X::~X() in C++03?

I don't want to actually call it, just use in SFINAE to figure if there exists a destructor for a given type.


回答1:


You can't get the function pointer of a destructor nor a constructor. Nevertheless a destructor always exist for a type, and you can't detect if its private with as access specifiers are not considered by SFINAE.

On the subject of invoking what would be the destructor of a scalar type, the standard says [class.dtor]/16:

[Note:the notation for explicit call of a destructor can be used for any scalar type name (5.2.4). Allowing this makes it possible to write code without having to know if a destructor exists for a given type. For example,

typedef int I;

I* p;

p->I::~I();

—end note]



来源:https://stackoverflow.com/questions/10858998/how-do-i-get-the-member-function-pointer-of-a-destructor

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