this指针的补充

上传人:痛*** 文档编号:244186035 上传时间:2024-10-03 格式:PPT 页数:20 大小:198.50KB
返回 下载 相关 举报
this指针的补充_第1页
第1页 / 共20页
this指针的补充_第2页
第2页 / 共20页
this指针的补充_第3页
第3页 / 共20页
点击查看更多>>
资源描述
单击此处编辑母版标题样式,this,指针,#include,class,Point,double,x, y ;,public :,void,setXY,(,double,a,double,b) x = a ; y = b ; ,void,printXY,() ,cout, x , y ,endl,; ;, ;,void main(),Point,obj1, obj2, obj3 ;,obj1 .,setXY,( 10, 15 ) ;,obj1 .,printXY,() ;,obj2 .,setXY,( 20, 25 ) ;,obj2 .,printXY,() ;,obj3 .,setXY,( 30, 35 ) ;,obj3 .,printXY,() ;,this,指针,#include,class,Point,double,x, y ;,public :,void,setXY,(,double,a,double,b) x = a ; y = b ; ,void,printXY,() ,cout, x , y ,endl,; ;, ;,void main(),Point,obj1, obj2, obj3 ;,obj1 .,setXY,( 10, 15 ) ;,obj1 .,printXY,() ;,obj2 .,setXY,( 20, 25 ) ;,obj2 .,printXY,() ;,obj3 .,setXY,( 30, 35 ) ;,obj3 .,printXY,() ;,obj1.x,obj1.y,obj2.x,obj2.y,obj3.x,obj3.y,this,指针,#include,class,Point,double,x, y ;,public :,void,setXY,(,double,a,double,b) x = a ; y = b ; ,void,printXY,() ,cout, x , y ,endl,; ;, ;,void main(),Point,obj1, obj2, obj3 ;,obj1 .,setXY,( 10, 15 ) ;,obj1 .,printXY,() ;,obj2 .,setXY,( 20, 25 ) ;,obj2 .,printXY,() ;,obj3 .,setXY,( 30, 35 ) ;,obj3 .,printXY,() ;,obj1.x,obj1.y,obj2.x,obj2.y,obj3.x,obj3.y,this,指针,#include,class,Point,double,x, y ;,public :,void,setXY,(,double,a,double,b) x = a ; y = b ; ,void,printXY,() ,cout, x , y ,endl,; ;, ;,void main(),Point,obj1, obj2, obj3 ;,obj1 .,setXY,( 10, 15 ) ;,obj1 .,printXY,() ;,obj2 .,setXY,( 20, 25 ) ;,obj2 .,printXY,() ;,obj3 .,setXY,( 30, 35 ) ;,obj3 .,printXY,() ;,obj1.x,obj1.y,obj2.x,obj2.y,obj3.x,obj3.y,向哪个对象,的数据成员赋值?,this,指针,#include,class,Point,double,x, y ;,public :,void,setXY,(,double,a,double,b) x = a ; y = b ; ,void,printXY,() ,cout, x , y x = a ; this-y = b ; ,obj1 .,setXY,( 10, 15,&obj1,) ;,成员函数隐含定义,this,指针,接受调用对象的地址,this,指针,#include,class,Point,double,x, y ;,public :,void,setXY,(,double,a,double,b) x = a ; y = b ; ,void,printXY,() ,cout, x , y x = a ; this-y = b ; ,this,指针,#include,class,Point,double,x, y ;,public :,void,setXY,(,double,a,double,b) x = a ; y = b ; ,void,printXY,() ,cout, x , y x = a ; this-y = b ; ,this,指针,#include,class,Point,double,x, y ;,public :,void,setXY,(,double,a,double,b) x = a ; y = b ; ,void,printXY,() ,cout, x , y ,endl,; ;, ;,void main(),Point,obj1, obj2, obj3 ;,obj1 .,setXY,( 10, 15 ) ;,obj1 .,printXY,() ;,obj2 .,setXY,( 20, 25 ) ;,obj2 .,printXY,() ;,obj3 .,setXY,( 30, 35 ) ;,obj3 .,printXY,() ;,obj1.x,obj1.y,obj2.x,obj2.y,obj3.x,obj3.y,通过调用函数的对象,this,指针获取对象地址,this,指针,#include,class,Point,double,x, y ;,public :,void,setXY,(,double,a,double,b) x = a ; y = b ; ,void,printXY,() ,cout, x , y ,endl,; ;, ;,void main(),Point,obj1, obj2, obj3 ;,obj1 .,setXY,( 10, 15 ) ;,obj1 .,printXY,() ;,obj2 .,setXY,( 20, 25 ) ;,obj2 .,printXY,() ;,obj3 .,setXY,( 30, 35 ) ;,obj3 .,printXY,() ;,10,15,obj1.x,obj1.y,obj2.x,obj2.y,obj3.x,obj3.y,this,指针,#include,class,Point,double,x, y ;,public :,void,setXY,(,double,a,double,b) x = a ; y = b ; ,void,printXY,() ,cout, x , y ,endl,; ;, ;,void main(),Point,obj1, obj2, obj3 ;,obj1 .,setXY,( 10, 15 ) ;,obj1 .,printXY,() ;,obj2 .,setXY,( 20, 25 ) ;,obj2 .,printXY,() ;,obj3 .,setXY,( 30, 35 ) ;,obj3 .,printXY,() ;,10,15,obj1.x,obj1.y,obj2.x,obj2.y,obj3.x,obj3.y,this,指针,#include,class,Point,double,x, y ;,public :,void,setXY,(,double,a,double,b) x = a ; y = b ; ,void,printXY,() ,cout, x , y ,endl,; ;, ;,void main(),Point,obj1, obj2, obj3 ;,obj1 .,setXY,( 10, 15 ) ;,obj1 .,printXY,() ;,obj2 .,setXY,( 20, 25 ) ;,obj2 .,printXY,() ;,obj3 .,setXY,( 30, 35 ) ;,obj3 .,printXY,() ;,10,15,obj1.x,obj1.y,obj2.x,obj2.y,obj3.x,obj3.y,在,obj1,上操作,10 , 15,20 , 25,30 , 35,this,指针,#include,class,Point,double,x, y ;,public :,void,setXY,(,double,a,double,b) x = a ; y = b ; ,void,printXY,() ,cout, x , y ,endl,; ;, ;,void main(),Point,obj1, obj2, obj3 ;,obj1 .,setXY,( 10, 15 ) ;,obj1 .,printXY,() ;,obj2 .,setXY,( 20, 25 ) ;,obj2 .,printXY,() ;,obj3 .,setXY,( 30, 35 ) ;,obj3 .,printXY,() ;,10,15,obj1.x,obj1.y,obj2.x,obj2.y,obj3.x,obj3.y,10 , 15,20 , 25,30 , 35,this,指针,#include,class,Point,double,x, y ;,public :,void,setXY,(,double,a,double,b) x = a ; y = b ; ,void,printXY,() ,cout, x , y ,endl,; ;, ;,void main(),Point,obj1, obj2, obj3 ;,obj1 .,setXY,( 10, 15 ) ;,obj1 .,printXY,() ;,obj2 .,setXY,( 20, 25 ) ;,obj2 .,printXY,() ;,obj3 .,setXY,( 30, 35 ) ;,obj3 .,printXY,() ;,10,15,obj1.x,obj1.y,obj2.x,obj2.y,obj3.x,obj3.y,10 , 15,20 , 25,30 , 35,在,obj2,上操作,this,指针,#include,class,Point,double,x, y ;,public :,void,setXY,(,double a,double,b) x = a ; y = b ; ,void,printXY,() ,cout, x , y ,endl,; ;, ;,void main(),Point,obj1, obj2, obj3 ;,obj1 .,setXY,( 10, 15 ) ;,obj1 .,printXY,() ;,obj2 .,setXY,( 20, 25 ) ;,obj2 .,printXY,() ;,obj3 .,setXY,( 30, 35 ) ;,obj3 .,printXY,() ;,10,15,obj1.x,obj1.y,20,25,obj2.x,obj2.y,obj3.x,obj3.y,10 , 15,20 , 25,30 , 35,在,obj2,上操作,this,指针,#include,class Simple,int,x, y ;,public :,void,setXY,(,int,a,int,b) x = a ; y = b ; ,void,printXY,() ,cout, x , y ,endl,; ;,void,constFun,( ), x + ; y + ; , ;,this,指针,#include,class Simple,int,x, y ;,public :,void,setXY,(,int,a,int,b) x = a ; y = b ; ,void,printXY,() ,cout, x , y ,endl,; ;,void,constFun,( ),x + ; y + ;, ;,正确,this,指针,#include,class Simple,int,x, y ;,public :,void,setXY,(,int,a,int,b) x = a ; y = b ; ,void,printXY,() ,cout, x , y ,endl,; ;,void,constFun,( ), x + ; y + ; , ;,const,this,指针,#include,class Simple,int,x, y ;,public :,void,setXY,(,int,a,int,b) x = a ; y = b ; ,void,printXY,() ,cout, x , y ,endl,; ;,void,constFun,( ),const,x +,;,y +,; , ;,void,constFun,(,const,Simple * const this,),错误,不能修改对象的数据成员,this,指针,是指向常量的常指针,this,指针,#include,class Simple,int,x, y ;,public :,void,setXY,(,int,a,int,b) x = a ; y = b ; ,void,printXY,() ,cout, x , y ,endl,; ;,void,constFun,( ),x +,;,y +,; , ;,
展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 管理文书 > 施工组织


copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!