2

I am studying my c++ lecture, and the professor gives a slide with this code example on. He says that because b1 is the first parent (so I think the first one implemented?), it has the same memory adress as the child class (Mi). Then, I am still confused why b2 is not equal to &mi, even though you specified it that way in Base1* b1 = &mi.

I thought it looked like this in memory (see picture), but I think, when looking at the fact that b2 == &mi is false, that this isn't correct. How should I change the picture to make it a correct representation of the memory layout?enter image description here

Mi mi;                  //MI inherits both from Base1 and Base2

Base1* b1 = &mi;        // Upcast

Base2* b2 = &mi;        // Upcast

//Suppose b1 is first parent

//now we test:

b1 == &mi;     //true

b2 == &mi;     //false
Jens
  • 141
  • 10

0 Answers0