#include <iostream>
using namespace std;
//基类:动物园讲解员
class Zoo_speaker{
protected:
string dance;
public:
Zoo_speaker(){}
Zoo_speaker(string dance):dance(dance){}
virtual void show(){
cout << "speak" << endl;
}
};
//狮子类
class Lion : public Zoo_speaker{
private:
string name;
int age;
double weight;
public:
Lion(){}
Lion(string name, int age, double weight, string dance):Zoo_speaker(dance),name(name), age(age), weight(weight){}
void show(){
cout << "Lion" << dance << endl;
}
};
//老虎类
class Tiger : public Zoo_speaker{
private:
string color;
public:
Tiger(){}
Tiger(string color, string dance):Zoo_speaker(dance),color(color){}
void show(){
cout << "Tiger" << dance << endl;
}
};
int main()
{
Lion l1("狮子王", 10, 120.3, "咆哮");
Zoo_speaker *p = &l1;
p -> show();
Tiger t1("golden", "喵喵");
p = &t1;
p -> show();
return 0;
}
20240611
最新推荐文章于 2024-11-05 17:16:24 发布