#include<iostream>
#include<string>
class Lovers{
public:
Lovers(std::string name){
this->name=name;
}
void kiss(Lovers*lovers);
void ask(Lovers *lovers,std::string something);
protected:
std::string name;
friend class Others;
};
class Boyfriend:public Lovers{
public:
Boyfriend(std::string name);
};
class Girfriend:public Lovers{
public :
Girfriend(std::string name);
};
class Others{
public :
Others(std::string name){
this->name=name;
}
void kiss(Lovers*lovers);
protected:
std::string name;
};
void Lovers::kiss(Lovers*lovers){
std::cout<<name<<"亲亲我们家的"<<lovers->name<<std::endl;
}
void Lovers::ask(Lovers *lovers,std::string something){
std::cout<<"宝贝儿"<<lovers->name<<"帮我"<<something<<std::endl;
}
Boyfriend::Boyfriend(std::string name):Lovers(name){
}
Girfriend::Girfriend(std::string name):Lovers(name){
}
void Others::kiss(Lovers *lovers){
std::cout<<name<<"亲一下"<<lovers->name<<std::endl;
}
int main(){
Boyfriend boyfriend("A君");
Girfriend x("B妞");
Others others("路人甲");
boyfriend.kiss(&boyfriend);
x.ask(&boyfriend,"洗衣服啦");
std::cout<<"\n当当当!传说中的路人甲登场。。。。。。。";
others.kiss(&x);
return 0;
}
相关文章
- 12-28C++中的默认参数规则
- 12-28C++中,new/delete和malloc/free的区别
- 12-28C++学习笔记--友元
- 12-28C++中的静态绑定和动态绑定
- 12-28vue中class类名根据绑定的值三元表达式或字符串拼接动态添加类名
- 12-28对比C++中的指针和引用
- 12-28C++中的类访问控制
- 12-28第二章 2.群中的等价关系 -- 陪集,共轭,正规子群与商群
- 12-28C++算法原理与实践(面试中的算法和准备过程)
- 12-28C++中\n与endl的区别