类和类之间访问私有变量

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();
}
相关推荐
菜鸟~noob23316 分钟前
【电子战】第三季预告—波武器与电子系统强力毁伤
开发语言·数据库·matlab·电子战
念何架构之路1 小时前
zap采样器与性能优化内幕
算法·性能优化·哈希算法
惊讶的猫1 小时前
工具选对之后还不够:商城 Agent 的参数与权限治理
开发语言·python
cmpxr_1 小时前
【MicroPython】如何刷新ESP8266的固件
开发语言·micropython
搭贝2 小时前
上厕所的时间搭好一套系统:AI自动生成实测
开发语言·人工智能·低代码·ai·php·搭贝
智感子2 小时前
智能称重·数据上云:从仪表读数到可追溯的计量凭证
开发语言·php
晒太羊的猫2 小时前
hot100动态规划刷题
算法·动态规划
\光辉岁月/2 小时前
7.javase-面向对象
java·开发语言
weixin_531094692 小时前
heap_4内存管理
java·开发语言·算法
余额瞒着我当琳2 小时前
红黑树的实现--红黑树的概念、规则、效率、结构、旋转、查找、验证
数据结构·c++·算法