资源描述
单击此处编辑母版标题样式,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 +,; , ;,
展开阅读全文