类和类之间访问私有变量

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();
}
相关推荐
一苓二肆10 小时前
PUMA机械臂matlab仿真正逆解与路径规划
开发语言·matlab
练习时长一年10 小时前
LeetCode热题100(分割等和子集)
算法·leetcode·职场和发展
Frank_refuel10 小时前
C++之继承
开发语言·c++
七号驿栈10 小时前
07_汽车信息安全算法在线验证工具(测试报告)
算法
sunfove11 小时前
Python 自动化实战:从识图点击、模拟真人轨迹到封装 EXE 全流程教学
开发语言·python·自动化
傻啦嘿哟11 小时前
Python网页自动化操作全攻略:从入门到实战
开发语言·python·自动化
啦哈拉哈11 小时前
【Python】知识点零碎学习4
python·学习·算法
哪有时间简史11 小时前
C++程序设计
c++
爱喝可乐的老王11 小时前
线性回归模型案例:广告投放效果预测
算法·回归·线性回归
筱歌儿11 小时前
TinyMCE-----word表格图片进阶版
开发语言·javascript·word