I'm having a scenario where i'm implementing multilevel inheritance but first level inheritance is specified as protected inheritance , but it is giving me compilation issue.
class A
{
protected:
int a1;
};
class B: protected A
{
protected:
int b1;
};
class C: public B
{
public:
C()
{
a1=10;
b1=20;
cout<<a1<<b1<<endl;
}
};
int main()
{
C c; //can access A class protected data
A* a= new C; //compilation error: cannot cast 'C'to its protected base class 'A'
}
My issue is when i do inheritance using protected access specified ,I'm able to access all A Class data members then why can't I'm able to have a pointer of A class type holding C object?