|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
#include <iostream>
#include <string>
using namespace std;
class Lovers{
public:
Lovers(string theName);
void kiss(Lovers *lover);
void ask(Lovers *lover, string sth);
protected:
string name;
friend class Others;
};
class BoyFriend : public Lovers{
public:
BoyFriend(string theName);
};
class GirlFirend : public Lovers{
public:
GirlFirend(string theName);
};
class Others{
public:
Others(string theName);
void kiss(Lovers *lover);
protected:
string name;
};
void Lovers::kiss(Lovers *lover){
cout << name << " Kiss " << lover->name << endl;
}
void Lovers::ask(Lovers *lover, string sth){
cout << "My Dear " << lover->name << " help me " << sth << endl;
}
BoyFriend::BoyFriend(string theName) : Lovers(theName){
};
GirlFirend::GirlFirend(string theName) : Lovers(theName){
};
Others::Others(string theName){
name = theName;
}
void Others::kiss(Lovers *lover){
cout << name << " Kiss " << lover->name << endl;
}
int main(){
BoyFriend boyfriend("Mike");
GirlFirend girlfriend("Lily");
Others others("John");
girlfriend.kiss(&boyfriend);
girlfriend.ask(&boyfriend, "wash clothes");
cout << "Now it's other's turn..." << endl;
others.kiss(&girlfriend);
return 0;
}
编译器在BoyFriend::BoyFriend(string theName) : Lovers(theName){};中报出[Error] ld returned 1 exit status |
|