类和类之间访问私有变量

cpp 复制代码
#include<iostream>
using namespace std;
class Building;
class Gooddey{

public:
	friend  Building;
	Gooddey();
	void visit();
	Building *building;
};
class Building{
	friend	class Gooddey;
public:
	Building(){
		this->age = 10;
		this->ac = 20;
	}
public:
	int age ;
private:
	int ac ;
};
Gooddey::Gooddey(){
	building = new Building;
}
void Gooddey::visit(){
	cout << building->age << endl;
	cout << building->ac << endl;
}
void test(){
	Gooddey p;
	p.visit();
}
int main(){
	test();
}
相关推荐
何陋轩17 分钟前
【重磅】悟空来了:国产AI编程助手深度测评,能否吊打Copilot?
人工智能·算法·面试
Rust研习社19 分钟前
从入门到实践:Rust 异步编程完全指南
开发语言·后端·rust
yaoxin52112323 分钟前
389. Java IO API - 获取文件名
java·开发语言·python
逸风尊者1 小时前
XGBoost模型工程使用
java·后端·算法
小苗卷不动1 小时前
OJ练习之疯狂的自我检索者(简单)
c++
LUVK_1 小时前
第七章查找
数据结构·c++·考研·算法·408
迷途之人不知返1 小时前
vector
c++
lhbian1 小时前
AI编程革命:Codex让脚本开发提速10倍
开发语言·汇编·jvm·c#
jiayong231 小时前
第 36 课:任务详情抽屉快捷改状态
开发语言·前端·javascript·vue.js·学习
khalil10201 小时前
代码随想录算法训练营Day-31贪心算法 | 56. 合并区间、738. 单调递增的数字、968. 监控二叉树
数据结构·c++·算法·leetcode·贪心算法·二叉树·递归