What's the difference between friendship and inheritance?

前端 未结 4 1100
轻奢々
轻奢々 2021-01-01 06:12

Suppose there are two classes A and B:

class A {};
class B {};

In what aspects differ the two examples below?

Example 1:

         


        
4条回答
  •  失恋的感觉
    2021-01-01 06:30

    In the context you're using, to answer your question to the best of my ability, friends simply allow your classes to share protected/private data, while inheritance will do the same, except there'll be a deeper relationship, where the classes are one in the same (such as with casting).

提交回复
热议问题