Where would you use a friend function vs. a static member function?

后端 未结 15 2246
[愿得一人]
[愿得一人] 2020-12-02 04:56

We make a non-member function a friend of a class when we want it to access that class\'s private members. This gives it the same access rights as a static member function w

15条回答
  •  无人及你
    2020-12-02 05:24

    The difference is clearly expressing the intent of the relationship between the class and the function.

    You use friend when you want to intentionally indicate a strong coupling and special relationship between two unrelated classes or between a class and a function.

    You use static member function when the function is logically a part of the class to which it is a member.

提交回复
热议问题