类和类之间访问私有变量

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();
}
相关推荐
吃我一窝jio4 小时前
Python与Go线程模型深度对比
java·开发语言·python
eggwyw5 小时前
C++ union 的一种妙用法
开发语言·c++
罗西的思考5 小时前
【轻量化复现大模型 / KIMI K3】MTP / EAGLE‑3 模块交互式演示
人工智能·深度学习·算法
ShineWinsu6 小时前
对于Qt:QHBoxLayout常见属性以及方法的解析
c++·qt·面试·gui·客户端·布局管理器·水平布局器
starzy19907 小时前
深入理解Scala隐式函数:自动类型转换
开发语言·后端·scala
小七在进步7 小时前
string的实现(1)
c++·笔记·visual studio
布莱克6059 小时前
Swift 循环与控制转移详解:从 for-in 到标签跳转
开发语言·ssh·swift·循环
kyle~9 小时前
模型预测控制(MPC)
算法·机器人·控制·传感器
敲上瘾10 小时前
Qt核心机制:信号与槽详解
开发语言·c++·qt·ui·qt6.3
联犀10 小时前
ai时代复杂项目的golang项目如何更好的与ai共舞:monorepo+gozero
开发语言·人工智能·golang