Question: for example, question. Assume that there are parent class A and Child class B.
A instantiate an object a B instantiate an object B
What is the address relationship between A and B in the memory. Are their first addresses the same?
Answer:
They do not have. Just like generating two other types of variables. Of course, the object B you instantiate is related to. The four bytes starting with object B are the virtual function table, followed by the data member of the base class, and then the data member of the subclass.
Peer: Where is the class object in C ++ in memory after it is instantiated? Heap or stack? I (thinking, but not sure): either in the stack or in the stack: under what circumstances, in the stack? Me: if the class object instance appears as a local variable in the stack, the scope ends, and the memory occupied by the class instance is released, the new class will be created in the heap in the form of a pointer, you must manually delete the file in the heap. Peer: Who controls stack allocation and recycling? Me: Operating System peer: What are the destructor of the class instance? Me (a little dizzy)