Here are my assumptions based on the question.
1) You have a case where you drop from C to and get the expected behavior.
2) You added a virtual function, and this action no longer works (while you can no longer retrieve data from A immediately after transferring to A, you get data that does not make sense to you).
If these assumptions are true, then the difficulties you are encountering are inserting a virtual table in B. This means that the data in the class is no longer aligned with the data in the base class (as bytes are added to the class, the virtual table is hidden from you ) A fun test would be to check the sizeof to see the growth of unknown bytes.
To solve this problem, you should not use direct access from A to C to collect data. You must add a getter function that is in and inherited from B and C.
Given your update in the comments, I think you should read this , it explains the virtual tables and memory layout, and how this compiler is dependent. This link explains in more detail what I explained above, but gives examples of pointers that are different values. Actually, I had WHY you asked the question incorrectly, but it looks like you still need the information. At the same time, the virtual table at this point is taken into account from C (note C-8 is 4, which, in my opinion, will be the size of the address required for the virtual table on a 32-bit system).
David d
source share