Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- class Animal{
- public:
- virtual Animal* copy()const =0;
- };
- class Dog:public Animal{
- public:
- Animal* copy()const{
- return new Dog(*this);
- }
- };
- class Cat: public Animal{
- public:
- Animal* copy()const{
- return new Cat(*this);
- }
- };
- class Frog: public Animal{
- public:
- Animal* copy() const{
- return new Frog(*this);
- }
- };
- class AnimalWezel{
- public:
- AnimalWezel* next;
- Animal* wsk;
- };
- class AnimalList{
- private:
- AnimalWezel* begin;
- AnimalWezel* end;
- public:
- AnimalList(): begin(0), end(0){}
- ~AnimalList();
- void add(Animal* a);
- AnimalList(const AnimalList&);
- AnimalList& operator=(const AnimalList&);
- };
- AnimalList::~AnimalList() {
- AnimalWezel* it;
- while(begin=0){
- it=begin;
- begin=begin->next;
- delete(it->wsk);
- delete(it);
- }
- begin=0;
- end=0;
- }
- void AnimalList::add(Animal* a){
- AnimalWezel* tmp;
- if(begin=0){
- begin=tmp;
- end=tmp;
- tmp->next=0;
- }
- else{
- end->next=tmp;
- tmp->next=0;
- end=tmp;
- }
- tmp->wsk=a;
- }
- AnimalList::AnimalList(const AnimalList& copy1) {
- AnimalWezel* it=copy1.begin;
- while(it!=0){
- this->add(it->wsk->copy());
- it=it->next;
- }
- }
- AnimalList& AnimalList::operator=(const AnimalList& copy1){
- AnimalWezel* it;
- while(begin=0){
- it=begin;
- begin=begin->next;
- delete(it->wsk);
- delete(it);
- }
- begin=0;
- end=0;
- it=copy1.begin;
- while(it!=0){
- this->add(it->wsk->copy());
- it=it->next;
- }
- return (*this);
- }
- int main(){
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement