I am little confused about vptr and representation of objects in the memory, and hope you can help me understand the matter better.

  1. Consider B inherits from A and both define virtual functions f(). From what I learned the representation of an object of class B in the memory looks like this:[ vptr | A | B ] and the vtbl that vptr points to contains B::f(). I also understood that casting the object from B to A does nothing except ignoring the B part at the end of the object. Is it true? Doesn't this behavior is wrong? We want that object of type A to execute A::f() method and not B::f().

  2. Are there a number of vtables in the system as the number of classes?

  3. How will a vtable of class that inherits from two or more classes look like? How will the object of C be represented in the memory?

  4. Same as question 3 but with virtual inheritance.

Edit
Report