類中默認(rèn)有一個(gè)對(duì)象的this指針,編譯器默認(rèn)加的
- this可以解決命名沖突
- 指針永遠(yuǎn)指向當(dāng)前對(duì)象
- *this永遠(yuǎn)指向本體
-非靜態(tài)成員方法才有指針
代碼這樣:class Person
{
public:
Person(int A)
{
this->A = A;
}
int A;
};
實(shí)際是這樣:class Person
{
public:
Person(Person* this,int A)
{
this->A = A;
}
int A;
};