0

When we made function as virtual in a class, compiler will set a static array at compile time which contains of addresses of all virtual functions and when we create an object for that class, __vptr is created and it will contain the starting address of the virtual table. But why can't __vptr is shared by all the objects of the same class?

kadina
  • 5,042
  • 4
  • 42
  • 83
  • 1
    How would you find the vptr at runtime? – fredoverflow Jul 02 '15 at 12:36
  • 1
    How does the runtime know what object is of which class? the vptr give an object its runtime identity, from a virtual function point of view. – tahsmith Jul 02 '15 at 12:37
  • 1
    The whole point of the __vptr is that you know that each object in a class hierarchy has one, and that its value changes depending on its place in the hierarchy. Even if all the objects of a single class have the same __vptr, not all the objects of a class hierarchy has the same one. – KABoissonneault Jul 02 '15 at 12:37

0 Answers0