Am a newbie to C++.
class A
{
public:
int i;
protected: //**--- [1]**
void set()
{
i=5;
cout<<i;
}
};
class B : public A
{
public:
void call()
{
A obj;
obj.set(); //**----[2]**
set(); //**---[3]**
}
};
int main()
{
B* b_obj = new B;
b_obj->call();
}
Why doesn't the code compiled if i try including [2] and not replacing [1] to public BUT it works if i compile including [3] alone?
Compiled error: error: ‘void A::set()’ is protected.
In short, My intention is to understand why base object cannot be called in derived class if the access specifier for the base class interface is set as protected.