#include <iostream>
using std::cout;
using std::endl;
class Animal
{
public:
virtual ~Animal() {}
virtual void talk() = 0;
};
class Dog : public Animal
{
public:
void talk() override;
};
void Dog::talk()
{
cout << "wuff" << endl;
}
class Cat : public Animal
{
public:
void talk() override;
};
void Cat::talk()
{
cout << "miau" << endl;
}
class Duck : public Animal
{
public:
void talk() override;
};
void Duck::talk()
{
cout << "quack" << endl;
}
void playWith(Animal& animal)
{
cout << "dieses Tier macht... ";
animal.talk();
}
int main()
{
Dog dog;
playWith(dog);
Cat cat;
playWith(cat);
Duck duck;
playWith(duck);
return 0;
}