I was working around with inheritance in C++. To my knowledge if you don’t specify, B will always inherit private from A.
So why does this code work:
struct A {};
struct B : A {};
int main(void)
{
A b = B();
return 0;
}
But this creates the "A is an inaccessible Base of B" error:
struct A {};
struct B : private A {};
int main(void)
{
A b = B();
return 0;
}
I would expect them to be the same?
>Solution :
Private inheritance is the default if the derived class is defined using the word class.
If you create it using struct, then inheritance is public by default.