如何获取析构函数的成员函数指针? [英] How do I get the member function pointer of a destructor?
问题描述
假设我有
struct X {
〜X(){}
};
什么是类型,如何获取 X的成员函数指针::〜X()
在C ++ 03中?
我不想实际调用它,只是在SFINAE中使用如果存在给定类型的析构函数。
您不能获取析构函数的函数指针或构造函数。然而,一个析构函数总是存在一个类型,你不能检测其 private
作为访问说明符不被 SFINAE 考虑。 p>
关于调用标量类型的析构函数的问题,标准表示 [class.dtor] / 16
:
[注意:显式调用析构函数的符号可用于任何标量类型名称(5.2.4)。允许这样做使得可以编写代码,而不必知道给定类型是否存在析构函数。例如,
typedef int I;
I * p;
p-> I ::〜I();
-end note]
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.
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]
这篇关于如何获取析构函数的成员函数指针?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!