They are not the same. In the first example, B
is-an-A
, in the second it isn't. So in the first case you can have code such as
void foo(const A& a);
which accepts A
and B
as arguments. With private inheritance, you could not do that. For example,
A a;
B b;
foo(a); // OK with private and public inheritance
foo(b); // OK only with public inheritance, i.e. B is an A.