Contents Up << >>

What does it mean that "friendship is neither inherited nor transitive"?

The privileges of friendship aren't inherited: derived classes of a friend aren't necessarily friends (I may declare you as my friend, but that doesn't mean I necessarily trust your kids). If class "Base" declares " f()" to be a friend, "f()" doesn't have any automatic special access rights to the extra stuff declared in derived class, "Derived."

The privileges of friendship aren't transitive: friends of a friend class aren't necessarily friends of the original class (a friend of a friend isn't necessarily a friend). E.g., if class "Fred" declares class " Wilma" as a friend, and class "Wilma" declares "f()" as a friend, " f()" doesn't necessarily have any special access rights to "Fred".