0

In the description

A class that contains a virtual pointer, but no other data except (possibly) virtual bases. In particular ...

What does virtual bases mean here? a dynamic base classs? or classes virtually inherited by the most derived class? I think it's the second explaination, but using gcc to dump-class-hierarchy will show that normally inherit from dynamic classes can make the most derived class nearly empty too, is there something wrong? below code will show that a class NearlyEmpty2 which not virtually inherited from two dynamic classes is a nearly empty class.

cpp code

struct Empty {};
struct NearlyEmpty { virtual void d() {}};
struct NearlyEmpty2: public NearlyEmpty, public Empty {};

output of g++ -fdump-class-hierarchy NearlyEmpty.cpp

Class NearlyEmpty2
   size=8 align=8
   base size=8 base align=8
NearlyEmpty2 (0x0x7fc7eaeed460) 0 **nearly-empty**
    vptr=((& NearlyEmpty2::_ZTV12NearlyEmpty2) + 16u)
  NearlyEmpty (0x0x7fc7eb044720) 0 nearly-empty
      primary-for NearlyEmpty2 (0x0x7fc7eaeed460)
  Empty (0x0x7fc7eb044780) 0 empty
ddwolf
  • 91
  • 2
  • 10
  • *"What does virtual bases mean here?"* Yes, I'm sure it refers to classes virtually inherited from (but not necessarily directly by the most derived class). As I read it, both virtual and regular bases are allowed, but virtual bases are explicitly mentioned because they add memory overhead. – HolyBlackCat Jan 03 '20 at 09:40
  • The *"In particular ..."* bits from the original quote actually contains the answer to your question. – Holt Jan 03 '20 at 09:41

0 Answers0