且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

C++:空类的对象的大小是多少?

更新时间:2022-03-22 01:58:25

引用 Bjarne Stroustrup 的 C++Style and Technique FAQ,大小不为零的原因是为了确保两个不同对象的地址不同".大小可以是 1,因为对齐在这里并不重要,因为实际上没有什么可看的.

Quoting Bjarne Stroustrup's C++ Style and Technique FAQ, the reason the size is non-zero is "To ensure that the addresses of two different objects will be different." And the size can be 1 because alignment doesn't matter here, as there is nothing to actually look at.