Advertisement
Guest User

Untitled

a guest
Nov 30th, 2015
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.11 KB | None | 0 0
  1. #pragma once
  2. class ArrayAbstract
  3. {
  4. public:
  5.     ArrayAbstract();
  6.     ArrayAbstract(int size);
  7.     ~ArrayAbstract();
  8.    
  9.    
  10.     int* to_array();
  11.     int& operator[](int i);
  12.     ArrayAbstract* operator=(ArrayAbstract* a);
  13.     virtual ArrayAbstract* operator+( ArrayAbstract*) = 0;
  14.     //ArrayAbstract* operator=(ArrayAbstract*);
  15.     virtual void foreach() = 0;
  16.     int get_size();
  17.  
  18. protected:
  19.     int size_;
  20.     int* array_ = nullptr;
  21.  
  22. };
  23.  
  24.  
  25. ArrayAbstract::ArrayAbstract()
  26. {
  27.     size_ = 10;
  28.     array_ = new int[size_];
  29. }
  30.  
  31. ArrayAbstract::ArrayAbstract(int size)
  32. {
  33.     size_ = size;
  34.     array_ = new int[size_];
  35. }
  36.  
  37.  
  38. ArrayAbstract::~ArrayAbstract()
  39. {
  40.     delete array_;
  41. }
  42.  
  43.  
  44.  
  45.  
  46. int * ArrayAbstract::to_array()
  47. {
  48.     int* ret_arr = new int[size_];
  49.     for (int i = 0; i < size_; ++i)
  50.     {
  51.         ret_arr[i] = array_[i];
  52.     }
  53.     return ret_arr;
  54. }
  55.  
  56. int & ArrayAbstract::operator[](int i)
  57. {
  58.     return array_[i];
  59. }
  60.  
  61. ArrayAbstract * ArrayAbstract::operator=(ArrayAbstract * a)
  62. {
  63.     size_ = a->size_;
  64.     array_ = new int[size_];
  65.     for (int i = 0; i < a->size_; ++i)
  66.         array_[i] = (*a)[i];
  67.     return this;
  68. }
  69.  
  70.  
  71. int ArrayAbstract::get_size()
  72. {
  73.     return size_;
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement