1.
class Animal{
public:
Animal(std::string theName);
std::string name;
}
class Pig:public Animal{
public:
Pig(std::string theName);
}
2.
#include<iostream>
#include<string>
class Lovers
{
public:
Lovers(std::string theName);
void kiss(Lovers *lover);
void ask(Lovers *lover,std::string something);
protected:
std::string name;
friend class Others;
};
class Boyfriend:public Lovers
{
public:
Boyfriend(std::string theName);
};
class Girlfriend:public Lovers
{
public:
Girlfriend(std::string theName);
};
class Others
{
public:
Others(std::string theName);
void kiss(Lovers *lover);
protected:
std::string name;
};
Lovers::Lovers(std::string theName)
{
name=theName;
}
void Lovers::kiss(Lovers *lover)
{
std::cout<<name <<"亲亲我们家的"<<lover->name<<std::endl;
}
void Lovers::ask(Lovers *lover,std::string something)
{
std::cout<<"宝贝儿"<<lover->name<<"帮我"<<something<<std::endl;
}
Boyfriend::Boyfriend(std::string theName):Lovers(theName)
{
}
Girfriend::Girfriend(std::string theName):Lovers(theName)
{
}
Others::Others(std::string theName)
{
name=theName;
}
void Others::kiss(Lovers *lover)
{
std::cout<<name<<"亲一下"<<lover->name<<std::endl;
}
int main()
{
Boyfriend boyfriend("A");
Girlfriend girlfriend("B");
Others others("路人甲");
girlfriend.kiss(&boyfriend);
girlfriend.ask(&boyfrieng,"洗衣服啦");
std::cout<<"\n路人甲登场。。。\n";
others.kiss(&girlfriend)
}
|