Base class function and derived class function having the same signature but inherited as protected .In main i have assigned derived class object to a base class pointer and i am trying to access the function .It causes error. Is it because of Protected?
class base{
public:
void test(){
cout<<"test in base\n";
}
};
class derived:protected base{
public:
void test(){
cout<<"test in derived\n";
}
};
int main(){
base *ptr;
derived obj;
ptr=&obj;
ptr->test();
return 0;
}
error:
In function 'int main()':
error: 'base' is an inaccessible base of 'derived'
ptr=&obj;
^~~
;
on line 42. Please include the error and the code in the question. – 463035818_is_not_a_number