每个对象都有一个this指针, 指向对象的内存地址。
this特点:
1.this只能在成员函数中使用,全局函数,静态函数不能使用this。成员函数 int fun(T *const, int p);其实默认了第一个参数就是T *const this。
2. this在成员函数的开始前构造,在成员函数的结束后清楚。
3. this会存放栈、寄存器、全局变量等,位置不定。
在上节基础上创建fun() ;
void dog::fun()
{
this->name = "gou";
cout << "name = " <<this->name<<endl;
}
dog成员函数使用指针this,指向类的成员name,赋值gou。