C++: What is the size of an object of an empty class?

后端 未结 16 1796
悲&欢浪女
悲&欢浪女 2020-11-22 11:54

I was wondering what could be the size of an object of an empty class. It surely could not be 0 bytes since it should be possible to reference and

16条回答
  •  深忆病人
    2020-11-22 12:40

    The standard states that all most derived objects have sizeof() >= 1:

    Unless it is a bit-field (class.bit), a most derived object shall have a non-zero size and shall occupy one or more bytes of storage. Base class sub-objects may have zero size. ISO/IEC FDIS 14882:1998(E) intro.object

提交回复
热议问题