Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.17 KB | None | 0 0
  1. class Vector {
  2. //a
  3. private:
  4. float size;
  5. long long startingIndex;
  6. double* data;
  7.  
  8. //b
  9. Vector(float size, long long startingIndex) : size{size}, startingIndex{startingIndex}
  10. {
  11. if(size<1)
  12. data = nullptr;
  13. else
  14. data  = new double(size);
  15. }
  16.  
  17. //c
  18. ~Vector() {
  19.         if (nullptr != data)
  20.         {
  21.             delete data;
  22.         }
  23.     }
  24. //d konstruktor kopiujacy
  25. Vector(const Vector& x){
  26.     this->size = x.size;
  27.     this->startingIndex = x.startingIndex;
  28.    
  29.      if (size > 0) {
  30.             data = new double[size]();
  31.             copy(x.data, x.data + x.size, this->data);
  32.         }
  33.         else
  34.             data = nullptr;
  35.  
  36. }
  37.  
  38. //f  para operatorow []
  39.  double& operator[](const size_t index) {
  40.         if (startingIndex + index > size - 2) {
  41.             throw std::out_of_range("out of range");
  42.         }
  43.         return data[startingIndex + index];
  44.     }
  45.  
  46.     const double& operator[](const size_t index) const {
  47.         if (startingIndex + index > size - 2) {
  48.             throw std::out_of_range("out of range");
  49.         }
  50.         return data[startingIndex + index];
  51.     }
  52.    
  53. //g     operator ()
  54. float operator()() const {
  55.         return size;
  56.     }
  57.  
  58. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement