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

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

    It is inherited - the derived class object will contain it, but it can't be accessed by member functions of the derived class.

提交回复
热议问题