#include <iostream>
using namespace std;
class A
{
public:
int memfunc(int i = 0)
{
cout << "A::memfunc" << endl;
}
static int clsfunc(int i = 0)
{
cout << "A::clsfunc" << endl;
}
};
int main()
{
int (*pcls)(int) = &A::clsfunc; // well
pcls = A::clsfunc; // well too, caus static-mem-func is a rvalue, will change to be a pointer
pcls(0); // ---- parameter is necessary!
(*pcls)(0); // ---- parameter is necessary!
A a;
int (A::*pmem)(int) = &A::memfunc; // well
// pmem = A::memfunc; // error, caus mem-func is a lvalue, cannot change to be a pointer
(a.*pmem)(0); // ---- parameter is necessary!
// (a.(*pmem))(0); // error, caus .* is a single operator
(&a->*pmem)(0); // ---- parameter is necessary!
// (&a->(*pmem))(0); // error, caus ->* is a single operator
return 0;
}
笔记:成员函数指针
最新推荐文章于 2023-06-29 18:25:58 发布