类中默认有一个对象的this指针,编译器默认加的
- this可以解决命名冲突
- 指针永远指向当前对象
- *this永远指向本体
- 非静态成员函数才有this指针
代码这样:class Person
{
public:
Person(int A)
{
this->A = A;
}
int A;
};
实际是这样:class Person
{
public:
Person(Person* this,int A)
{
this->A = A;
}
int A;
};
类中默认有一个对象的this指针,编译器默认加的
代码这样:class Person
{
public:
Person(int A)
{
this->A = A;
}
int A;
};
实际是这样:class Person
{
public:
Person(Person* this,int A)
{
this->A = A;
}
int A;
};