首页 > 代码库 > 类的内存分部

类的内存分部

class A {
    char k[3];
public:
    virtual void a() {};
};

class B : public virtual A {
    char j[3];
public:
    virtual void bb() {};
};

class C :public virtual B {
    char i[3];
public:
    virtual void cc() {};
};

sizeof(A) = 4+3+1 = 8;

sizeof(B) = sizeof(A)+4+3+1 = 16;

sizeof(C) = sizeof(B)+4+3+1 = 24;

 

类的内存分部