class c1 {
public:
c1 (int x1){
x=x1;
p[0]=c1::a1;
p[1]=c1::b1;
}
int (c1::*p[2]) (void);
int a1();
int b1();
void disp ();
private:
int x;
};
int c1::a1()
{
return x;
}
int c1::b1 ()
{
return 2*x;
}
void c1::disp ()
{
cout<<*p[0](); //error C2064: term does not evaluate to a function
}
void main()
{
c1 x (2);
x.disp ();
cout<<x.*p[1] (); //error C2065: 'p' : undeclared identifier
// error C2109: subscript requires array or pointer type
// error C2064: term does not evaluate to a function
}
编译时,两处调用成员函数指针数组元素出现错误,如何解决?谢谢