c++ - 指向函数成员的已删除指针的类型

标签 c++ c++11 function-pointers

类型:

std::remove_pointer<int(*)(int)>::type

int(int)。这段代码:

#include <iostream>
#include <type_traits>

using namespace std;

int main()
{
   cout << boolalpha;
   cout << is_same<remove_pointer<int(*)(int)>, int(int)>::value;
   cout << endl;
}

打印“真”。但是,“函数成员”的(书面)类型是什么?

#include <iostream>
#include <type_trais>

using namespace std;

struct A {};

int main()
{
    cout << boolalpha;
    cout << is_same<remove_pointer<int(A::*)(int)>, int(int)>::value;
    cout << endl;
}

返回 false。而像 int A::(int) 这样的东西会抛出编译错误(无效类型)。

最佳答案

指向成员的指针不是指针。

remove_pointer 不会改变类型。

关于c++ - 指向函数成员的已删除指针的类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14524556/

相关文章:

c++ - 成员函数指针和对象工厂模式

c++ - 为什么 C++ 允许 std::map 的类型没有默认构造函数,而 std::pair 则不允许?

c++ - 访问 Qt 小部件线程安全

派生对象上基于 C++11 范围的 for 循环

c++ - 针对不同数据类型的单一结构调整方法

CUDA 函数指针

c - typedef 函数指针和 extern 关键字

c++ - Qt:如何创建文件(其路径需要目录)?

c++ - 如何正确删除已知二维大小的二维数组?

c++ - 在过渡到 C++11 期间管理外部库(例如 boost)