类和类之间访问私有变量

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();
}
相关推荐
gCode Teacher 格码致知1 小时前
Pandas教学-17:Series与Dataframe的关系
开发语言·python·pandas
发量惊人的中年网工2 小时前
分公司访问总部ERP慢怎么办?SD-WAN组网的排查与验收要点
服务器·开发语言·php
下页、再停留2 小时前
【C#桌面客户端系列学习-15】生成可视化图表之折线图、柱状图、饼状图
开发语言·c#
ShineWinsu2 小时前
对于JavaScript:操作元素的解析
开发语言·前端·javascript·面试·web·dom·元素
罗西的思考3 小时前
【Agentic RL】Dressage Staleness 控制深度分析
人工智能·算法·机器学习
quaer3 小时前
弗洛伊德算法--判圈法寻找环的入口O(n) O(1)
数据结构·算法
益莱储中国3 小时前
深度解析:RF 实验室从 5G迈向 6G 的过程中保持技术领先与设备升级的路径
开发语言·php
丰色木夕4 小时前
Ubuntu22.04下源码编译安装USD-Brep
c++·ubuntu·nvidia·usd-brep
benchmark_cc4 小时前
Python 量化系统如何设计统一的数据访问接口:从策略解耦到数据层架构
开发语言·python·数据分析·pandas·量化交易·股票数据·quantdash
高晶5 小时前
无乘法器实现LC二阶滤波器:基于移位运算的快速算法与四种精度推导
算法·设计模式·程序员