类和类之间访问私有变量

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 分钟前
征程6|YOLOv5x 在 Horizon J6 平台的完整部署实战(上)
算法
青 春 记 忆8 分钟前
LeetCode 104. 二叉树的最大深度|Python 解法详解
python·算法·leetcode
watersink14 分钟前
机器学习关联分析
人工智能·算法·机器学习
牛油果子哥q20 分钟前
C++STL算法超全精讲:排序/查找/去重/遍历/最值/合并全套API、仿函数、Lambda适配、实战避坑
开发语言·c++·算法
Xeon_CC27 分钟前
用C++编写屏幕准星
开发语言·c++
AI服务老曹30 分钟前
摄像机安装AI视频分析完整流程:从现场物理安装、硬解配置到算法POC效果验证
人工智能·算法·音视频
孤存52233 分钟前
c语言动态内存管理
c语言·开发语言·算法
牛阿大35 分钟前
MPC算法
算法
祖力551 小时前
快速学会数据结构中的链式队列与循环队列
linux·c语言·数据结构·算法
冰暮流星1 小时前
javascript之webstorage用法
开发语言·javascript·ecmascript