假设我有
struct X {
~X() {}
};
C++03中X::~X()
的成员函数指针是什么类型,如何获取?
我不想实际调用它,只是在 SFINAE 中使用它来确定是否存在给定类型的析构函数。
最佳答案
您无法获取析构函数或构造函数的函数指针。尽管如此,一个类型总是存在析构函数,并且您无法检测 SFINAE 是否不考虑它的带有 as 访问说明符的 private
。
关于调用什么是标量类型的析构函数,标准说 [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]
关于c++ - 如何获取析构函数的成员函数指针?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10858998/