11.数据共享和成员特性.ppt

11.4.2 this指针的实质 this指针的指向 当类实例化时,this指针指向对象自己;而在类的声明时,指向类本身。 当成员函数的形参名与该类的成员变量名同名时,必须用this指针来显式区分。 例 : class CPoint { public: CPoint( int x = 0, int y = 0 ) { this- x = x; this-y = y; } void Offset ( int x = 0, int y = 0 ) { (*this). x = x; (*this).y = y; } void Print() const { coutPoint(xPos, yPos) endl; } private: int x, y; }; 11.4.2 this指针的实质 this指针的指向 当类实例化时,this指针指向对象自己;而在类的声明时,指向类本身。 当成员函数的形参名与该类的成员变量名同名时,必须用this指针来显式区分。 在静态成员函数中是不能使用this指针的。 this指针的类型 在普通成员函数中, 在类常成员函数中, 类名 * const this = 类名; const类名 * const this = 类名; 第11章 数据共享和成员特性 11.1 静态成员

文档评论(0)

1亿VIP精品文档

相关文档