类成员的4种使用方式

来源:互联网 发布:诚信通软件下载 编辑:程序博客网 时间:2024/06/01 08:51
#include <iostream.h>
class  student
{public:
 int no;
 void show(){
cout <<"no="<<no<<endl;}
};
int main()
{
    student s1;//对象
    s1.no=1;
s1.show();


    student & x=s1;//引用
    x.no=4;
x.show();




    student * p=&s1;//指针
p->no=2;
p->show();


(*p).no=3;//指针内容
(*p).show();


return  0;
}
0 0
原创粉丝点击