一.定义
用于存放对象空间起始地址的变量
二.声明对象指针的一般形式
*类名 对象指针名;
例如:
Box *p;**
Box a(10,12, 20);
p = &a;
三.通过对象指针访问成员的方法
*对象指针名->成员名
或 (对象指针名).成员名
四. 指向对象数据成员的指针变量定义
*数据类型名 指针变量名;
class Time
{ public:
int hour;
int minute;
int sec;
Time(int,int,int);
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;
Time *p2=&t1;
cout<<*p1<<endl;
t1.get_time( );
p2->get_time( );
}