第五周程序阅读(3)
来源:互联网 发布:小型网络机柜 编辑:程序博客网 时间:2024/05/18 22:10
#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;}
运行结果:
学习心得:
首先定义指向整型数据的指针变量p1,并使p1指向t1.hour,输出p1所指向的数据成员t1.hour,然后调用对象的成员函数,定义指向类的对象的指针变量p2,并使p2指向t1。调用所指对象的的函数,然后再定义指向类的公共成员函数的指针变量p3,使p3指向Time类公用成员函数,最后调用对象所指的成员函数即(t1.get_time())
0 0
- 第五周程序阅读(3)
- 第五周 阅读程序(3)
- 第五周 阅读程序(3)
- 第五周程序阅读(3)
- 第五周程序阅读
- 第五周阅读程序
- 第五周 程序阅读
- 第五周项目零:阅读程序(3):指针类
- 第五周 程序阅读——指针(3)
- 第五周程序阅读(2)
- 第五周程序阅读(4)
- 第五周 阅读程序(1)
- 第五周程序阅读(6)
- 第五周 阅读程序(2)
- 第五周 阅读程序(4)
- 第五周 阅读程序(5)
- 第五周 阅读程序(6)
- 第五周 阅读程序(1)--指针
- 原:计算机的多维学习方法
- 项目经理所在乎的事情
- TCP/IP知识总结面试题之Socket服务
- BZOJ 3560 DZY Loves Math V
- HOOK 钩子拦截WM_DEVICECHANGE消息
- 第五周程序阅读(3)
- thinkphp中的模型替换很容易混淆,解决办法如下
- android apk签名
- 2-3 Mifare S50的访问控制条件
- 定义一个日期Date,该类对象存放一个日期,可以提供的操作有:void :printDate(); //显示日期,格式如“日期是:2010年6月8日”void
- wireshark抓包详细图文教程-04
- 使用tab自动补全mysql命令
- opencv提取轮廓z
- linux下的目录含义和内容