Firstly, let us see the wrong version.
class A {
protected:
int price;
};
class C;
class B: public A {
public:
void test(const A& a, const B& b, const C& c);
};
class C: public B {
};
void B::test(const A& a, const B& b, const C& c) {
price=0;
a.price; // bug
b.price;
c.price;
}
int main()
{
A a;
B b;
C c;
b.test(a,b,c);
return 0;
}
We can not visit price through a, which is the object of base class. However, when delete this line, it gets right after all.