#include <iostream>
#include <vector>
using namespace std;
class Animal
{
public:
void parler()
{
cout << "je sais pas parler car je suis un animal générique" << endl;
}
};
class Chat : public Animal
{
private:
int i = 0;
public:
void parler()
{
cout << "miaou" << i << endl;
i++;
}
};
class Crapaud : public Animal
{
public:
void parler()
{
cout << "crooaaaa" << endl;
}
};
int main()
{
vector<Animal> S;
S.push_back(Chat());
S.push_back(Crapaud());
for (Animal &a : S)
{
a.parler();
}
}
int main()
{
vector<Animal*> S;
S.push_back(new Chat());
S.push_back(new Crapaud());
for (Animal*& a : S)
{
a->parler();
}
}
#include <memory.h>
int main()
{
vector< shared_ptr<Animal> > S;
S.push_back(shared_ptr<Animal>(new Chat()));
S.push_back(shared_ptr<Animal>(new Crapaud()));
for (shared_ptr<Animal>& a : S)
{
a->parler();
}
}