When should you use 'friend' in C++?

前端 未结 30 2001
孤街浪徒
孤街浪徒 2020-11-22 10:12

I have been reading through the C++ FAQ and was curious about the friend declaration. I personally have never used it, however I am interested in exploring the language.

30条回答
  •  一整个雨季
    2020-11-22 10:52

    The tree example is a pretty good example : Having an object implemented in a few different class without having an inheritance relationship.

    Maybe you could also need it to have a constructor protected and force people to use your "friend" factory.

    ... Ok, Well frankly you can live without it.

提交回复
热议问题