问题及代码
/*
*ALL rights reserved.
*文件名称: 初学对象5
*作者:李长鸿
*完成时间:2015.4.8
*问题描述:阅读程序
*/
#include <iostream>
using namespace std;
class Time
{
public:
Time(int,int,int);
void output_time( );
int hour;
int minute;
int sec;
};
Time::Time(int h,int m,int s)
{
hour=h;
minute=m;
sec=s;
}
void Time::output_time( )
{
cout<<hour<<":";
cout<<minute<<":" <<sec<<endl;
}
int main( )
{
Time t1(10,13,56);
int *p1=&t1.hour; //指向数据成员的指针
cout<<*p1<<endl;
t1.output_time( );
Time *p2=&t1; //指向对象的指针
p2->output_time( );
void (Time::*p3)( ); //指向成员函数的指针
p3=&Time::output_time;
(t1.*p3)( );
return 0;
}
总结:最后那个指向成员函数的代码还是不清楚。再努力吧,弄懂它!!

被折叠的 条评论
为什么被折叠?



