Why does the size of a derived class include private members from the base class?

前端 未结 7 1722
谎友^
谎友^ 2021-02-09 19:52

I have the following code:

class A {
  private:
    int i;
 };

class B : public A {
 private:
  int j;
 };

When I check sizeof(B)

7条回答
  •  [愿得一人]
    2021-02-09 20:05

    i dont know what language this is, but when you inherit the original object still exists. that is why you can still call base.method()

提交回复
热议问题