The following code gives the error: 'B' is an inaccessible base of 'D'.
Why does this happen? The constructor of B is public which means it should be inherited by class D even though the inheritance is protected / private.
Can someone tell me a workaround as well? Except of course making the inheritance public.
#include <iostream>
#include <typeinfo>
using namespace std;
class B
{ int i;
public:
B() { i=1; }
int get_i() { return i; }
};
class D: private B
{ int j;
public:
D() { j=2; }
int get_j() {return j; }
};
int main()
{
B *p= new D;
return 0;
}
Thank you!