技术栈

类和类之间访问私有变量

程序那事2024-01-19 15:45
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();
}
上一篇:python数字图像处理基础(九)——特征匹配
下一篇:鸿蒙OS4.0兼容性测试
相关推荐
编程大师哥
几秒前
匿名函数 lambda + 高阶函数
java·python·算法
isyangli_blog
2 分钟前
OpenDayLight (Carbon 版本) 启动与组件安装
开发语言·php
vb200811
10 分钟前
FastAPI APIRouter
开发语言·python
Benszen
12 分钟前
KVM虚拟化解决方案
开发语言·perl
会编程的土豆
13 分钟前
Go 语言反射(Reflection)详解
开发语言·后端·golang
東雪木
15 分钟前
多线程与并发编程 专属复习笔记
java·开发语言·笔记·java面试
我叫袁小陌
24 分钟前
算法解题思路指南
算法
MC皮蛋侠客
27 分钟前
C++17 多线程系列(五):C++17 并行算法——从串行到并行的零成本迁移
c++·多线程
地平线开发者
30 分钟前
Conv+BN+Add+ReLU 融合机制简介
算法·自动驾驶
热门推荐
01GitHub 镜像站点02【AI】2026 年具身智能模型和世界模型总结03【踩坑记录 | 第一篇】微软商店无法使用时,如何手动安装 OpenAI Codex?附`.msix`文件系统错误解决方法042026 年 AI 编程工具终极横评:Cursor vs Claude Code vs Copilot vs Windsurf05CC-Switch & Claude 基于 Linux 服务器安装使用指南06裂开!ChatGPT 居然开始要手机号验证,附详细解决方法07Codex 接入 DeepSeek API 完整配置文档08DeepSeek V4 + Claude Code thinking mode 400 错误修复方案09几个好用的ip纯净度检测网站10Codex 下载安装指南:Windows 和 macOS 官方版下载