I have two classes (sheep and wolf) derivating from one (animal). I created a vector of shared pointer like that:
std::vector<std::shared_ptr<animal>> animals;
for (int i = 0; i < n_sheep; i++) {
auto my_sheep = std::make_shared<sheep>();
animals.push_back(std::move(my_sheep));
}
for (int i = 0; i < n_wolf; i++) {
auto my_wolf = std::make_shared<wolf>();
animals.push_back(std::move(my_wolf));
}
What is the best way to iterate through this vector and to know the difference between those smart_ptr ?
Something like that:
for (int i = 0; i < animals.size(); i++) {
if (animals[i] == sheep)
//TODO
if (animals[i] == wolf)
//TODO
Thank you all.