|
Oh, I didn't think about the landlord's problem clearly, and I talked about it.
The first floor is right, "object copy" does not affect virtual tables.
Ra was originally referencing a class B object, and this would not change.
ra = c;
This sentence just modifies the base class sub-object of that referenced object. You cannot modify the virtual table. Once you modify it, it means that it still refers to a class b object (), but it has a virtual table of class A. Then, the following sentence:
delete pa;
It will not work, and the destructor will not be called accurately. When the class is complicated, it is easy to get a memory leak. |
|