在C ++中的朋友函数 [英] Friend functions in C++

查看:114
本文介绍了在C ++中的朋友函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个与C ++中的朋友函数有关的疑问。 Friend函数不是claas的成员函数,可以直接从main调用。所以,如果我们在 private 中保留 friend public 部分。我一般注意到 friend 函数总是在公共部分。在什么情况下,我们应该在 private 中保留 friend 函数。

I have a doubt related to friend functions in C++. Friend function is not a member function of the claas and can be invoked directly from the main. So, what difference does it make if we keep the friend function within the private or the public part of the class. I have generally noticed that the friend functions are always in the public part. In what scenario we should keep the friend function within private.

推荐答案

编译器不会注意朋友函数是否在类的私有或公共(或保护)部分。大多数人都把它放在公共部分,但它会公开显示,无论你把它放在哪里。

The compiler does not pay any attention to whether a friend function is in the private or public (or protected) section of a class. Most people put it in the public section, but it'll be publicly visible regardless of where you put it.

这篇关于在C ++中的朋友函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆