标签:turn .com get nbsp set new public asi sizeof
在这里列出了空类,类有函数,值,没有函数的大小,注意Class也是默认字节对齐
#include <stdio.h> class x { }; class cx { public: cx() { } ~cx() { } }; class cxHasVal { public: cxHasVal() { } ~cxHasVal() { } int a; char y; }; class cxHasValFunc { public: cxHasValFunc() { } ~cxHasValFunc() { } int a; char y; int getASize() { return sizeof(a); } void setA() { a = 5; } }; int main() { x emptyX; int emptySize = sizeof(x); printf("size of empty class is %d\n\n",emptySize); cx *classx = new cx(); int clsizePt = sizeof(classx); int clsize = sizeof(cx); printf("size of class point is %d\n",clsizePt); printf("size of class is %d\n\n",clsize); cxHasVal *hasVal = new cxHasVal(); hasVal->a = 12; int hasValSize = sizeof(hasVal); int rVal = sizeof(cxHasVal); printf("size of class Point has val is %d\n",hasValSize); printf("size of class has val is %d\n\n",rVal); cxHasValFunc *hasValFunc = new cxHasValFunc(); int hasValFuncSize = sizeof(hasValFunc); int rValFunc = sizeof(cxHasValFunc); printf("size of class Point has val is %d\n",hasValFuncSize); printf("size of class has val Func is %d\n\n",rValFunc); return 0; }
运行结果:
标签:turn .com get nbsp set new public asi sizeof
原文地址:https://www.cnblogs.com/anlia/p/9083652.html