#include iostreamusing namespace std;using stdcout;class Dogpublic void show protectedprivate int value = 66; int ptr; static int sta;;int main Dog wc; cout sizeofwc endl; return 0;输出为什么是16
输出结果为16的原因是因为类Dog中有一个int类型的成员变量value和一个int类型的指针成员变量ptr,它们分别占用4个字节的内存空间。此外,由于类中存在静态成员变量sta,它在类中只有一份拷贝,不会占用对象的内存空间。因此,sizeof(wc)的结果为16。
原文地址: https://www.cveoy.top/t/topic/iFrL 著作权归作者所有。请勿转载和采集!