"Zealot" <> wrote in message
news:cijcan$18oh$...
> class Base
> {
> protected:
> int var;
> };
>
> class ChildB : public Base
> {};
>
> class ChildA : public Base
> {
> void foo( ChildB* B )
> {
> var = B->var; C2248..
> }
> };
>
> why I can not process ChildB's member var ??
>
Because ChildB is not derived from ChildA. Access to protected members from
a derived class must be made through a pointer to, reference to, or object
of the derived class itself (or any class derived from that class).
Using your previous code for Base and ChildB
class ChildC : public ChildA {};
class ChildA : public Base
{
void foo(ChildA* a, ChildB* b ChildC* c)
{
a->var; // fine
b->var; // error
c->var; // fine
}
};
john
|