in Java, 1. you need to check next!=null 2. if B and D in different packages, D's next (inherited), which is a reference to a B's instance, cannot see the B's prev. if you really need to access the member directly, change it to "public" or add a public method to return the reference (preferred).
【在 b***i 的大作中提到】 : class B { : protected: : B* next; : B* prev; : }; : class D : public B { : public: : void foo() { : if (next && next->prev) // error: why? : return;
b*n
10 楼
template class B { friend D; protected: B *next; B *prev; }; class D: public B { public: void foo() { if (next && next->prev) return; } };
【在 i**p 的大作中提到】 : in Java, : 1. you need to check next!=null : 2. if B and D in different packages, D's next (inherited), which is a : reference to a B's instance, cannot see the B's prev. : if you really need to access the member directly, change it to "public" or : add a public method to return the reference (preferred).