您的位置:首页 > 其它

第五周阅读程序三

2015-04-05 16:32 357 查看

(3) 阅读程序,写出程序的运行结果并理解:

#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;
}

阅读输出:10

10:13:56

10:13:56

10:13:56

实际运行结果:



学习心得:与阅读的结果相同,主要演示了三种指向数据成员,指向对象,指向成员函数的指针的运用方法。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: