Lets say I have two classes
Widget
^
|
Window
and I have another class Application:
Defined as follows
class Application
{
public:
...
private:
friend Widget;
};
This will not give Window access to Applications protected and private members. Is there a way to accomplish this without declaring Window and any subsequent “Widget” as a friend of Application?
No it is not possible.
friendship is not inheritable.Also,
friendship indicates a intentional strong coupling between two entities So if your design indeed demands such a strong coupling go ahead and make themfriends.friendship breaking encapsulation is a far too misunderstood concept.