#include <iostream>
#include <vector>
#include <utility>
class Animal {
public:
Animal() { std::cout << "Animal()" << std::endl; };
~Animal() { std::cout << "~Animal()" << std::endl; };
virtual void eat() { std::cout << "Animal is eating" << std::endl; };
};
class Bear : public Animal {
public:
Bear() { std::cout << "Bear()" << std::endl; };
~Bear() { std::cout << "~Bear()" << std::endl; };
void eat() { std::cout << "Bear is eating" << std::endl; };
};
class Zebra : public Animal {
public:
Zebra() { std::cout << "Zebra()" << std::endl; };
~Zebra() { std::cout << "~Zebra()" << std::endl; };
void eat() { std::cout << "Zebra is eating" << std::endl; };
};
int main()
{
Bear bear;
Zebra zebra;
std::vector<Animal*> animalsp;
animalsp.push_back(&bear);
animalsp.push_back(&zebra);
for (auto i : animalsp) {
i->eat();
}
std::vector<Animal> animals;
animals.push_back(std::move(bear));
animals.push_back(std::move(zebra));
for (auto i : animals) {
i.eat();
}
return 0;
}