I,
The object is in the heap.ProgramManually released the memory.
When the object is in the stack, the system automatically releases the memory after the program runs.
This variable records the memory address of each object and then uses the indirect operator-> to access its members.
This variable records the memory address of each individual object, and this Pointer Points to each individual object, so
The memory address of this variable output by different objects is also different.
This variable stores the object address, so this pointer is the pointer to the object.
This pointer is created and deleted by the compiler.
2. The following is an example:
# Include <stdlib. h>
# Include <iostream>
Using namespace STD;
Class
{
Public:
A () {cout <"memory address of this variable:" <This <Endl ;}
Int get_number () const {return number ;}
Void set_number (int x) {number = x ;}
PRIVATE:
Int number;
};
Int main ()
{
A;
Cout <"& A:" <& A <Endl;
A. set_number (100 );
Cout <"a. I:" <A. get_number () <Endl;
A B;
Cout <"& B:" <& B <Endl;
B. set_number (1000 );
Cout <"B. I:" <B. get_number () <Endl;
Return 0;
}