#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; }
运行结果:
知识点总结:
void (Time::*p3)( ); //指向成员函数的指针
p3=&Time::output_time;
(t1.*p3)( );
学习心得:
好好学习 天天向上
时间: 2024-09-30 11:37:23