首页 新闻 会员 周边

C++:成员函数作友元函数

-1
悬赏园豆:5 [已解决问题] 解决于 2020-05-23 12:52

include <iostream>

include <string>

using namespace std;

//class goodBoy;
class Building{
//friend class goodBoy;
friend void goodBoy::visit();
public:
Building(){
this->m_SittingRoom = "客厅";
this->m_BeddingRoom = "卧室";
}
public:
string m_SittingRoom;
private:
string m_BeddingRoom;
};
class goodBoy{
public:
goodBoy(){
build = new Building;
}

void visit(){
    cout << "好朋友正在访问 " << this->build->m_SittingRoom << endl;
    cout << "好朋友正在访问 " << this->build->m_BeddingRoom << endl;
}

private:
Building * build;
};

void test03(){
goodBoy * boy = new goodBoy;
boy->visit();

}

int main(){
test03();
return 0;
}
这个为什么报error: use of undeclared identifier 'goodBoy'这个错误啊;小白一枚

牛坤的主页 牛坤 | 初学一级 | 园豆:193
提问于:2020-05-21 22:42

你把问题再编辑一下,使用插入代码,这样子我们比较好阅读代码

Conan-jine 3年前
< >
分享
最佳答案
1

在这插入代码

收获园豆:5
Conan-jine | 小虾三级 |园豆:1272 | 2020-05-21 22:57

谢谢,我重新发布了一个

牛坤 | 园豆:193 (初学一级) | 2020-05-21 23:09

@牛坤: 嘿嘿,既然这帖子没用了,给我个结贴呗,非常感谢!

Conan-jine | 园豆:1272 (小虾三级) | 2020-05-21 23:22
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册