These two days I found that with the problem more clearly understand a thing, the more detailed the problem, will understand very thoroughly, do not need to remember, now think of how comfortable to get rid of rote memorization
Question 1:this What is a pointer pointer?
Question 2: Why is this pointer called this?
Question 3:this What is the pointer pointer?
Question 4:this Does the pointer have space? If so, where is it?
Question 5:this where is the pointer used?
What is the implementation mechanism of the question 6:this pointer?
Legacy 1: Temporarily first as a pointer to this (requires the following questions to pave the way to know)
Legacy 2: (Requires the following questions to pave the way to know)
Resolution 3: A member variable in a class or a member function is called this call, meaning that the object of this class is called, this pointer is equivalent to the object of this class
Solution 4: The pointer is a space, not to mention I in the resolution 3 said this is the object of this class (to solve 3 said is the equivalent, you say is "is", conflict AH), the object is the instantiation of the class, how can no space, space again which--------------? New object, this space on the heap, directly built object, this space on the stack
Solve 5:this is the object of this class, in the class haunt, in the class using member variables or member functions, you can directly use, the front slightly write a This, can write not write, you can also add yourself, for example, but some cases are required to write, for example, the landlord has been doing the two days is to encapsulate thread, extended function , I want the callback function of the thread to use the member function, but the invocation of the callback function is normal call, I can only upload this to the thread callback function to use the member function
Resolution 6: Parse two assembly diagrams, provided that fun () and a are all members of the Fkone
Figure one, 01351047 see this, figure two is the disassembly in the disassembly of the display symbol name, you can see that this is ebp-4
1. Build the object of this class, open space, the location of the ESP is the end of the object address, the class has a member variable, so that the location of the ESP is the member variable, that is, the object's first address + 4 bytes behind
2.01351041 give the value of ESP to EBP
3.ebp-4 is the first address of the object of this class, explaining that the so-called this is the first address of the object, it also shows that the member variable or function is through the object's first address (here you can see the function of this and what is a, continue in depth)
4. I say this is false, there is no this pointer, I do not see the pointer in the assembly this thing, see is ebp-4 just------------ no this thing
5. I say this is true, the existence of pointers is the preservation of things to the address to explain, ebp-4 is not the address of the object, 01351047 can see the object's first address placed in the EAX register, then this time eax inside is the object's first address, EAX is not a pointer (here is the implementation of this mechanism, is to put the address of the object in the register, and then use the register to find member functions or member variables, there is no this thing, but I also said 5 of this thing, see this, do not know you have not seen, I this article title meaning, here also solves the legacy of 1 and left 2, left 2,this English explanation is in this class can use, also solved why I say the equivalent)-------- have this thing
(PanPen120 original, if there are suggestions, light message)
C + + Basics of this pointer (either, or no, this is not a problem)