Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- class ArrayAbstract
- {
- public:
- ArrayAbstract();
- ArrayAbstract(int size);
- ~ArrayAbstract();
- int* to_array();
- int& operator[](int i);
- ArrayAbstract* operator=(ArrayAbstract* a);
- virtual ArrayAbstract* operator+( ArrayAbstract*) = 0;
- //ArrayAbstract* operator=(ArrayAbstract*);
- virtual void foreach() = 0;
- int get_size();
- protected:
- int size_;
- int* array_ = nullptr;
- };
- ArrayAbstract::ArrayAbstract()
- {
- size_ = 10;
- array_ = new int[size_];
- }
- ArrayAbstract::ArrayAbstract(int size)
- {
- size_ = size;
- array_ = new int[size_];
- }
- ArrayAbstract::~ArrayAbstract()
- {
- delete array_;
- }
- int * ArrayAbstract::to_array()
- {
- int* ret_arr = new int[size_];
- for (int i = 0; i < size_; ++i)
- {
- ret_arr[i] = array_[i];
- }
- return ret_arr;
- }
- int & ArrayAbstract::operator[](int i)
- {
- return array_[i];
- }
- ArrayAbstract * ArrayAbstract::operator=(ArrayAbstract * a)
- {
- size_ = a->size_;
- array_ = new int[size_];
- for (int i = 0; i < a->size_; ++i)
- array_[i] = (*a)[i];
- return this;
- }
- int ArrayAbstract::get_size()
- {
- return size_;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement