基类中的私有元素是否会增加派生类的大小?

Gho*_*ost 1 c++ inheritance

// inheritence experiment

#include"stdafx.h"
#include<iostream> 

using namespace std;

class base
{
private:
    int i;
};

class derived: public base
{
private:
    int j;
};

int main()
{
    cout << endl << sizeof(derived) << endl << sizeof(base);
    derived o1;
    base o2;
    cout << endl << sizeof(o1) << endl << sizeof(o2); 
}
Run Code Online (Sandbox Code Playgroud)

我得到这个输出:

8
4
8
4

为什么会这样?基类的私有数据成员不会继承到派生类中,那么为什么我得到8个字节,派生的大小和o1?

Dan*_*Dan 9

私人成员是继承的.您无法从派生类访问它们.