Agnew's reaction was in place. Let me explain a little more. Increasing the code, I print the size of the Base1 and table object, as well as the addresses of the three table objects created by the new operator:
A Base1 object is 8 bytes A table object is 12 bytes A table object is being constructed at 0x002977C0 A table object is being constructed at 0x002977CC A table object is being constructed at 0x002977D8
As you can see, these objects are located at a distance of 12 bytes from each other in memory.
Now type in the addresses that pBase [0], pBase [1] and pBase [2] give:
pBase[0] is at 0x002977C0 pBase[1] is at 0x002977C8 pBase[2] is at 0x002977D0
Now let's see what happens: the pointers that we return are located at a distance of 8 bytes. This is due to the fact that pointer arithmetic is performed on a pointer whose type is Base1 , and since Base1 is 8 bytes long, which the compiler does, translate pBase[n] into pBase + (n * sizeof(Base1)) .
Now you can understand exactly why the first GetRow() works and why you crashed into the second.
source share