指向类的成员函数的指针
指向类的成员函数的指针程序如下,和书上写的一样,但是会出错,请指教。
#include<iostream.h>
class mc
{
public:
int f()
{
return 1;
}
};
typedef int (mc::*pp)();
void main()
{
mc a;
pp p=&mc::f;
cout<<a.*p()<<endl;
}
错误如下:
--------------------Configuration: b - Win32 Debug--------------------
Compiling...
b.cpp
D:\Program Files\Microsoft Visual Studio\MyProjects\b\b.cpp(15) : error C2064: term does not evaluate to a function
Error executing cl.exe.
b.obj - 1 error(s), 0 warning(s)