0

Are objects of a subclass guaranteed to be the same size as objects of the superclass if they don't add data members?

Let us say that the subclass doesn't add add the first virtual method, so if the subclass has a vtbl the superclass also has a vtbl.

If it's not guaranteed in the spec, is it still true in practice (e.g., Windows and Linux running on Intel, with VC++, g++, clang)?

Swiss Frank
  • 1,985
  • 15
  • 33
  • 4
    Does this answer your question? [Is C++ allowed to increase the derived class size if there're no new member variables compared to the base class?](https://stackoverflow.com/questions/19949737/is-c-allowed-to-increase-the-derived-class-size-if-therere-no-new-member-vari) or [Size of a derived class without any additional data-members](https://stackoverflow.com/questions/57792947/size-of-a-derived-class-without-any-additional-data-members) – walnut Dec 30 '19 at 02:08
  • Short answer: no. Just as there is no guarantee (in the standard) that a class with virtual functions will have a vtable (even if it is a common implementation choice). Practically, within the constraints you have described, it MAY happen, but is not required to. – Peter Dec 30 '19 at 02:09
  • I would suggest focusing the question on the last part and making it a bit more concrete, so that it won't be a duplicate of the ones I posted. In particular I think there might be a definitive answer in the Itanium C++ ABI for e.g. Linux on x64. I don't know where the ABI used by VC++ on Windows can be found. – walnut Dec 30 '19 at 02:22

0 Answers0