在类中,只有非静态成员变量,是每个对象所私有的,所以类的大小就是类中非静态成员变量的大小。
#include<iostream>
#include<cstdio>
using namespace std;
class T{
int a; // 非静态成员变量 属于类的某一个对象-> size = sizeof(int)
void func_a(){ // 非静态成员函数 不属于类的某一对象-> size = 0
}
static int b; // 静态成员变量 不属于类的某一对象-> size = 0
static void func_b(){ // 静态成员函数 不属于类的某一对象-> size = 0
}
};
T::b == 10;
int main()
{
cout<<sizeof(T)<<endl;
return 0;
}