Agnew's response was spot on. Let me explain a little more. By augmenting your code, I print out the size of a Base1
and a table
object as well as the addresses of the three table
objects as they are 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 those objects are spaced 12 bytes apart from each other in memory.
Now, let's print out 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 look at what happens: the pointers we get back are spaced 8 bytes apart. This is because the pointer arithmetic is done on an pointer whose type is Base1
and since Base1
is 8 bytes longs what the compiler does is to translate pBase[n]
into pBase + (n * sizeof(Base1))
.
Now you should be able to understand exactly why the first GetRow()
works and why you crash on the second.