this pointer
- Every member function (including construction and destruction) has a this pointer
- The this pointer points to the calling object, that is, the members of the current object can be accessed through the this keyword
访问成员变量: this->成员名;
访问成员函数: this->函数名();
note:
- The type of this pointer is class type * const (class name * const), which is an rvalue.
- The this pointer itself does not occupy size , it is not part of the object, so it will not affect the result of sizeof.
- The scope of this is inside the class member function.
- The this pointer is the first default hidden parameter of the class member function. The compiler automatically maintains the transmission, and the class writer cannot display the transmission.
- This pointer can only be used in non-static member functions of the class, not any other functions.
函数的结尾声明为const:函数内部不允许修改对象本身,调用本对象非const方法就会报错。