![](https://img-blog.csdnimg.cn/20201014180756926.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
友元
没有金刚钻,也木有刷子
个人学习记录而已,主要供自己查看,如有不当请见谅。
展开
-
成员函数做友元
#include<iostream>using namespace std;#include<string>//类做友元class Home;class Goodfriend{public: Goodfriend(); Home *home; void visit();//让visit函数可以访问home的私有成员 void visit2();//让visit2函数不可以访问home的私有成员};class Home{ //告诉编译器,Goodf.原创 2021-02-25 10:46:20 · 262 阅读 · 0 评论 -
类做友元
1.类做友元#include<iostream>using namespace std;#include<string>//类做友元class Home;class Goodfriend{public: Goodfriend(); Home *home; void vist();//参观函数,访问home的属性};class Home{ //Goodfriend类是本类的好朋友,可以访问本类中私有成员 friend class Goodfri原创 2021-02-25 10:32:08 · 118 阅读 · 0 评论 -
全局函数做友元
1.目的:让一个函数或者类访问另一个类中的私有成员2.关键字:friend3.友元的三种实现:全局函数做友元 类做友元 成员函数做友元#include<iostream>using namespace std;#include<string>class Home{ // goodfriend全局函数是Home的好朋友,可以访问Home中的私有成员 friend void goodfriend(Home *home);public: Home()原创 2021-02-24 17:23:10 · 211 阅读 · 0 评论