C ++中的朋友声明 - 公共和私有之间的区别 [英] Friend declaration in C++ - difference between public and private

查看:232
本文介绍了C ++中的朋友声明 - 公共和私有之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人告诉我,在公共或私人领域声明一个朋友类是有区别的,但我似乎不能在网上找到任何东西,我不知道他们知道他们是什么谈论。

Someone told me that there is a difference between declaring a friend class in the public or private areas of the class, but I can't seem to find anything about this online, and I'm not sure they knew what they were talking about.

我的意思是:

class A
{
 public: 
      friend class B;
 };

class A
{
 private: //or nothing as the default is private
      friend class B;
 };

是否有区别?

推荐答案

不,没有什么区别 - 你只是告诉B类是A类的朋友,现在可以访问它的私有和受保护的成员。

No, there's no difference - you just tell that class B is a friend of class A and now can access its private and protected members, that's all.

这篇关于C ++中的朋友声明 - 公共和私有之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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