类和类之间访问私有变量

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();
}
相关推荐
xiaowu08029 分钟前
C# task任务异步编程提高UI的响应性
开发语言·c#
kill bert3 小时前
Java八股文背诵 第四天JVM
java·开发语言·jvm
√尖尖角↑3 小时前
力扣——【1991. 找到数组的中间位置】
算法·蓝桥杯
Allen Wurlitzer3 小时前
算法刷题记录——LeetCode篇(1.8) [第71~80题](持续更新)
算法·leetcode·职场和发展
低头专研4 小时前
Markdown标题序号处理工具——用 C 语言实现
c语言·开发语言·typora·markdown文件标题编号·md文件标题序号
百锦再5 小时前
五种常用的web加密算法
前端·算法·前端框架·web·加密·机密
刚入门的大一新生6 小时前
C++初阶-C++入门基础
开发语言·c++
你是理想6 小时前
wait 和notify ,notifyAll,sleep
java·开发语言·jvm
碳基学AI6 小时前
北京大学DeepSeek内部研讨系列:AI在新媒体运营中的应用与挑战|122页PPT下载方法
大数据·人工智能·python·算法·ai·新媒体运营·产品运营
forestsea6 小时前
Python进阶编程总结
开发语言·python·notepad++