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

前端 未结 7 1726
谎友^
谎友^ 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:26

    all member variables are inherited. the private protected public modifiers only alter who has access to those variables

提交回复
热议问题