类和类之间访问私有变量

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();
}
相关推荐
先做个垃圾出来………2 分钟前
差分数组(Difference Array)
java·数据结构·算法
向上的车轮3 分钟前
基于go语言的云原生TodoList Demo 项目,验证云原生核心特性
开发语言·云原生·golang
The Chosen One9854 分钟前
C++ : AVL树-详解
开发语言·c++
zzyzxb9 分钟前
std::enable_shared_from_this
c++
SNAKEpc1213815 分钟前
QML和Qt Quick
c++·qt
PH_modest15 分钟前
【Qt跬步积累】—— 初识Qt
开发语言·qt
hansang_IR25 分钟前
【题解】洛谷 P4286 [SHOI2008] 安全的航线 [递归分治]
c++·数学·算法·dfs·题解·向量·点积
乐迪信息25 分钟前
乐迪信息:AI摄像机在智慧煤矿人员安全与行为识别中的技术应用
大数据·人工智能·算法·安全·视觉检测
GanGuaGua33 分钟前
Linux系统:线程的互斥和安全
linux·运维·服务器·c语言·c++·安全
怀旧,42 分钟前
【C++】18. 红⿊树实现
开发语言·c++