|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
#include <iostream>
#include <string>
class Lovers
{
public:
Lovers();
void kiss();
};
Lovers::Lovers()
{
}
void Lovers::kiss()
{
std::cout << "正在亲吻!!!.................." << std::endl;
}
class Boyfriend:public Lovers
{
public:
void zhui(std::string name);
void fuwo();
Boyfriend(std::string name);
//protected:
std::string boyname;
};
Boyfriend::Boyfriend(std::string name)
{
boyname = name;
}
void Boyfriend::fuwo()
{
std::cout << "我正在做俯卧撑............." << std::endl;
}
void Boyfriend::zhui(std::string name)
{
std::cout << name << " 请问可以追你吗?!!!" << std::endl;
}
class Girlfriend:public Lovers
{
public:
void ask(std::string name,std::string whater);
Girlfriend(std::string name);
protected:
std::string girlname;
//friend class Boyfriend; //这里说明Boyfriend类和Girlfriend类是友元关系
};
Girlfriend::Girlfriend(std::string name)
{
girlname = name;
}
void Girlfriend::ask(std::string name,std::string whater)
{
std::cout << name << "你给我去做" << whater << "完成了我就答应你!!!" << std::endl;
}
int main()
{
Boyfriend boyf("九尾狐");
Girlfriend girlf("封芯狐");
boyf.zhui(girlf.girlname); //这里调用Girlfriend类里的girlname 我用了友元关系还是提示" 'girlname' : cannot access protected member declared in class 'Girlfriend'"
girlf.ask(boyf.boyname,"一万次俯卧撑");
boyf.fuwo();
boyf.kiss();
return 0;
}
求朋友帮我看看 看了1一个小时也没解决了 :dizzy: |
|