#include<iostream>
using namespace std
;
class Animal
{
public:
virtual void speak()
{
cout
<<"动物在说话"<<endl
;
}
};
class Cat:public Animal
{
public:
void speak()
{
cout
<<"小猫在说话"<<endl
;
}
};
class Dog:public Animal
{
public:
void speak()
{
cout
<<"小狗在说话"<<endl
;
}
};
void doSpeak(Animal
&animal
)
{
animal
.speak();
}
void test01()
{
Cat cat
;
Dog dog
;
doSpeak(cat
);
}
int main()
{
test01();
return 0;
}
转载请注明原文地址: https://lol.8miu.com/read-21479.html