c++ - 如何获取析构函数的成员函数指针?

标签 c++ destructor pointer-to-member c++03

假设我有

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/

相关文章:

java - 我可以通过字符串编译 C++ 源代码吗?

C++ 调用嵌套模板类析构函数

c++ - 当对象包含指针成员时,堆栈上对象破坏的段错误?

使用函数指针映射时的c++调用函数

c++ - 使用 Boost 的 bool 表达式

c++ - 将十六进制值视为单精度或 double 值

c++ - 如何在命名空间中应用名称查找

c++ - 这行代码在 C++ 类中是什么意思?

c++ - 从指针到成员的类模板推导

c++ - 指向在 C++ 中自动返回 'type' 的模板成员的指针?