注册 登录
编程论坛 C++教室

指向成员函数的指针问题

呜呜1 发布于 2013-10-15 21:36, 412 次点击
#include<iostream>
using  namespace  std;
class Time
{public:
Time(int,int,int);
int  hour;
int  minute;
int  sec;
void  get_time();
};
Time::Time(int h,int m,int s)
{hour=h;
minute=m;
sec=s;
}
void Time::get_time()
{cout<<hour<<":"<<minute<<":"<<sec<<endl;}
int  main()
{
    Time  t1(10,13,56);
    int  *p1=&t1.hour;
    cout<<*p1<<endl;
    t1.get_time();
    Time  *p2=&t1;
    p2->get_time();
    void  (Time::*p3)();
    p3=& Time::get_time();
    (t1.*p3)();
    return  0;
}
'运行报错,显示Time::get_time' : illegal call of non-static member function,为什么啊
2 回复
#2
peach54602013-10-16 06:18
p3=& Time::get_time();
编译器不是说得很清楚了吗?
get_time不是静态的
#3
呜呜12013-10-16 12:41
回复 2楼 peach5460
是滴,p3=&Time::get_time();去掉()就运行出来了
1