类和类之间访问私有变量

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();
}
相关推荐
dllmayday7 分钟前
Qt/QML + C++ 双向数据绑定(MVVM 模式的几种常用方法(ChatGPT)
开发语言·c++·qt
Mxsoft61912 分钟前
AR远程定位偏差救场!某次现场故障,SLAM算法精准对齐设备模型!
算法·ar
han_hanker16 分钟前
统一拦截异常 @RestControllerAdvice
java·开发语言·数据库
liu****18 分钟前
一.脚手架介绍以及部分工具使用
开发语言·数据结构·c++·手脚架开发
Hello娃的23 分钟前
【量子力学】Hohenberg-Kohn 定理
人工智能·算法
资深web全栈开发26 分钟前
深入理解 Google Wire:Go 语言的编译时依赖注入框架
开发语言·后端·golang
老马啸西风31 分钟前
成熟企业级技术平台 MVE-010-IGA(Identity Governance & Administration,身份治理与管理)平台
人工智能·深度学习·算法·职场和发展
ohoy32 分钟前
EasyPoi 数据脱敏
开发语言·python·excel
fish_xk32 分钟前
c++类和对象(上)
c++