I have the following code involving multi-level inheritance in C++. I want to verify the accessibility of data members for the object d defined in the main in the inheritance chain. I have summarized the accessibility as the following and was wondering if this is how object d sees its members!
A:
a1 public
a2 protected
a3 private
B:
A::a1 private
A::a2 private
A::a3 NOT accessible here
b1 public
b2 protected
b3 private
C:
A::a1 NOT accessible here
A::a2 NOT accessible here
A::a3 NOT accessible here
B:b1 protected
B:b2 protected
B:b3 NOT accessible here
c1 public
c2 protected
c3 private
D:
A::a1 NOT accessible here
A::a2 NOT accessible here
A::a3 NOT accessible here
B:b3 NOT accessible here
B:b1 protected
B:b2 protected
C:c1 public
C:c2 protected
C:c3 NOT accessible here
d1 public
d2 protected
d3 private
struct A
{
A() {}
public:
int a1;
protected:
int a2;
private:
int a3;
};
struct B: private A
{
B() :
A() {}
public:
int b1;
protected:
int b2;
private:
int b3;
};
struct C : protected B
{
C() :
B() {}
public:
int c1;
protected:
int c2;
private:
int c3;
};
struct D : public C
{
D() :
C() {}
public:
int d1;
protected:
int d2;
private:
int d3;
};
int main()
{
const D d;
}