what is the size of empty class in C++,java?

前端 未结 8 2123
北恋
北恋 2020-12-03 17:35

What is the size of an empty class in C++ and Java? Why is it not zero? sizeof(); returns 1 in the case of C++.

8条回答
  •  天涯浪人
    2020-12-03 17:57

    Because every C++ object needs to have a separate address, it isn't possible to have a class with zero size (other than some special cases related to base classes). There is more information in C++: What is the size of an object of an empty class? .

提交回复
热议问题