the usefulness of 1.this pointers:
The this pointer for an object is not part of the object itself and does not affect the results of the sizeof (object). This scope is within a class, when a non-static member of a class is accessed in a Non-static member function of a class, and the compiler automatically passes the address of the object itself as an implied parameter to the function. That is, even if you do not write the this pointer, the compiler adds this at compile time, as an implied parameter of a non-static member function, and access to each member is done through this. For example, call date. Setmonth (9) <===> setmonth (&date, 9), this helps complete the conversion.use of 2.this pointers: One scenario is to use return *this when returning the class object itself in a Non-static member function of a class, and in another case where the parameter is the same as the member variable name, such as This->n = N (cannot write n = n). 3. This pointer program example: This pointer exists in the member functions of a class , point to the address of the class instance where the called function is located. According to the following procedure, this pointer #include <iostream.h> class Point {Private:int x, y; Public:point (int A, int b) {x=a; y=b;} void Movepoint (int a, int b) {x+=a; y+=b;} void print () {cout<< "x=" <<x<< "y=" <<Y<<ENDL;} }; void Main () {point point1 (10,10); Point1. Movepoint (2,2); Point1.print (); When the object Point1 calls the Movepoint (2,2) function, the address of the Point1 object is passed to the this pointer. The prototype of the Movepoint function should be void movepoint (point *this, int a, int b); The first argument is a pointer to the class object that we didn't see when we defined the member function because it was implied in the class. This point1 address is passed to this, so it is explicitly written in the Movepoint function: void movepoint (int a, int b) {this->x +=a; this-> y+= b;} As you can tell, Point1 calls the function, that is, the POINT1 data member is called and the value is updated.4. A classic answer to this pointer:When you enter a house, you can see the table, chairs, floors, etc., but the house you do not see the whole picture. For an instance of a class, you can see its member functions, member variables, but the instance itself.This is a pointer that always points you to this instance itself