c++ - Why can friend class have access to Base class private data through Derived class -



c++ - Why can friend class have access to Base class private data through Derived class -

this first time post question here.

class base of operations { private: int base; friend class question; }; class derived : public base{ private: int super; }; class question{ public: void test(base& base, derived & derived) { int value1 =base.base; // no problem, because question friend class of base of operations int value2 =derived.super; // compile error, because question not friend class of base of operations // question here int value3 =derived.base; // no compile error here, not understand why. } };

the question indicated in lastly row of class question.

friend applies of members of type, whether or not type inherited. stress point: members shared.

this means question class has access members of base, int base::base. whether accesses fellow member through instance of derived irrelevant, because actual fellow member beingness accessed declared on base.

c++ friend

Comments

Popular posts from this blog

maven fortify plugin : Unable to load build session with ID XXXXX .. See log file for more details -

c# - Primavera WebServices does not return any data -

android - Display emoji panel with genymotion - keyboard/touch input? -