类和类之间访问私有变量
发布时间:2024年01月19日
#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();
}
文章来源:https://blog.csdn.net/2301_80429791/article/details/135698131
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如若内容造成侵权/违法违规/事实不符,请联系我的编程经验分享网邮箱:chenni525@qq.com进行投诉反馈,一经查实,立即删除!