#include <iostream>
#include <memory>
using namespace std;
class zwierze{
public:
virtual ~zwierze() = default;
virtual void odglos() = 0;
};
class kot : public zwierze{
public:
void odglos() override{
cout<<"Miaaaaau"<<endl;
}
};
class pies : public zwierze{
public:
void odglos() override{
cout<<"Hau hau"<<endl;
}
};
class tworcazwierzat{
public:
virtual ~tworcazwierzat() = default;
virtual unique_ptr<zwierze> stworzzwierze() = 0;
};
class tworcakotow : public tworcazwierzat{
public:
unique_ptr<zwierze> stworzzwierze() override{
return make_unique<kot>();
}
};
class tworcapsow : public tworcazwierzat{
public:
unique_ptr<zwierze> stworzzwierze() override{
return make_unique<pies>();
}
};
int main() {
tworcakotow stworzkota;
tworcapsow stworzpsa;
unique_ptr<zwierze> kot = stworzkota.stworzzwierze();
unique_ptr<zwierze> pies = stworzpsa.stworzzwierze();
kot->odglos();
pies->odglos();
return 0;
}
To embed this project on your website, copy the following code and paste it into your website's HTML: