类和类之间访问私有变量

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();
}
相关推荐
大鱼>6 分钟前
DSPy:LLM程序自动编译与提示词优化
开发语言·人工智能·python·深度学习
撩妹帝九歌14 分钟前
Java文件写入与编码、字节数组、字符集、字符编解码 一文打通!
java·开发语言
星核0penstarry22 分钟前
Solon AI v4.0.4 技术分析:Java Agent 框架的兼容性突破与选型考量 基于 OSCHINA 2026-07-30 报道及公开技术资料整理
java·开发语言·人工智能
加油码28 分钟前
共享内存详解:原理、系统调用与高性能进程间通信
linux·c语言·c++
昨夜星河入梦来29 分钟前
postman接口测试报错503的解决方法
开发语言·postman
spider_xcxc1 小时前
Jenkins 遇见 Argo CD:构建可靠 GitOps 流水线的实战指南
java·开发语言·servlet
June`1 小时前
常量内存和只读缓存
c++·人工智能·算法·cuda
一条大祥脚1 小时前
ABC468 扫描线|贡献法|二阶差分|线段树优化DP
数据结构·算法
IT小盘1 小时前
16-Prompt版本管理-从手工修改到可追踪配置系统
开发语言·人工智能·python·prompt
happyprince1 小时前
篇2-bitsandbytes-具体观-算法与实现剖析
算法