What's the difference between friendship and inheritance?
问题 Suppose there are two classes A and B: class A {}; class B {}; In what aspects differ the two examples below? Example 1: class C : public A, public B {}; Example 2: class C { //private friend class A; friend class B; } 回答1: A friend can touch the private parts (pun only slightly intentional! ;) ) of whatever it is friend of, but nothing of A and B are part of C - it just means that " A and B can touch C 's private bits"). Anything "less" than private is of course also available to A and B ,