C++ - Friend友元能继承吗
来源:互联网 发布:免费医疗软件 编辑:程序博客网 时间:2024/05/01 03:36
友元不能被继承:即,基类的友元未必是子类的友元;某类型的友元的子类未必是此类型的友元。
详细的,可以看以下两节:What does it mean that "friendship isn't inherited, transitive, or reciprocal"?
Just because I grant you friendship access to me doesn't automaticallygrant your kids access to me, doesn't automatically grant your friendsaccess to me, and doesn't automatically grant meaccess to you.
- I don't necessarily trust the kids of my friends. The privileges offriendship aren't inherited.Derived classes of afriend aren't necessarilyfriends. Ifclass Fred declares that classBase is afriend,classesderived from Base don't have any automatic specialaccess rights toFred objects.
- I don't necessarily trust the friends of my friends. The privilegesof friendship aren't transitive. Afriend of a friend isn't necessarily afriend. Ifclass Fred declares classWilma as a friend, andclassWilma declaresclass Betty as a friend,class Betty doesn'tnecessarily have any special access rights to Fred objects.
- You don't necessarily trust me simply because I declare you myfriend. The privileges of friendship aren't reciprocal. Ifclass Freddeclares thatclass Wilma is afriend, Wilma objects have specialaccessto Fred objects butFred objects do not automatically have special accessto Wilma objects.
What is inherited from the base class?
In principle, a derived class inherits every member of abase class except:- its constructor and its destructor
- its operator=() members
- its friends
- C++ - Friend友元能继承吗
- 友元friend和继承(C++)
- [C++]friend
- C++ protected friend 继承
- [C++] friend class
- C++::Class Friend
- C++——friend
- C++:友元函数friend
- C++friend用法简单总结
- C++-友元(friend)
- friend
- friend
- Friend
- Friend
- friend
- friend
- Friend
- friend
- C语言深度解剖【第一章问题】
- 导入/导出Excel
- MS-VC 使用MAP文件快速定位错误行
- NSManagedObject实例的值copy
- DBMS_XMLSTORE
- C++ - Friend友元能继承吗
- 移植thttpd嵌入式web服务器(转)
- 开发者必备的SQL性能优化基本功
- httpservletrequest cannot be resolved to a type
- SQL Server 2008 定时作业的制定(SQL2005参考此方法)
- Chrome源代码分析之进程和线程模型(四)
- oracle xml处理
- ASP.NET MVC Action以强类型的方式接收表单数据
- zoj2016Play on words(判断有向图是否存在欧拉回路通路)