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

后端 未结 16 1787
悲&欢浪女
悲&欢浪女 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:43

    I think it is so because as 1 byte is the smallest memory unit that can be used as a placeholder, and it cannot give zero size as it will not be possible to create an array of objects ..

    and the thing you said "This was a little surprising to me since I was expecting it to be of the size of the machine word (32 bits or 4 bytes)." will be true for reference variable(macine words) of type empty(),not size of class itself(which is abstract data type),

提交回复
热议问题