class B
{
protected:
int x;
public:
B(int i=28) { x=i; }
virtual B f(B ob) { return x+ob.x+1; }
void afisare(){ cout<<x; }
};
class D: public B
{
public:
D(int i=-32):B(i) {}
B f(B ob) { return x+ob.x-1; }
};
void test6()
{
B *p1=new D, *p2=new B, *p3=new B(p1->f(*p2));
p3->afisare();
}
The main just calls the function test6(); My question is, why does the compiler throw an error on the 3rd line, at int x declaration, with the message :
In member function 'virtual B D::f(B)' :
error: 'int B::x' is protected
error: within this context
PS : The example is from an exam so the faulty indentation and other "leaks" are intentionally.