给定一个班级
class C {
public:
int f (const int& n) const { return 2*n; }
int g (const int& n) const { return 3*n; }
};
p我们可以像这样定义一个函数指针C::f。
int (C::*p) (const int&) const (&C::f);
的定义p可以使用 a 进行拆分typedef:
typedef int (C::*Cfp_t) (const int&) const;
Cfp_t p (&C::f);
为了确保p不会改变(p = &C::g;例如),我们可以这样做:
const Cfp_t p (&C::f);
现在,p这种情况下的类型是什么?我们如何在p不使用 typedef 的情况下完成最后一个定义?我知道typeid (p).name ()无法区分最外面的 const 因为它产生
int (__thiscall C::*)(int const &)const