Gistrec

MyArray (у T нет оператора присваивания)

Jan 19th, 2018
506
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.81 KB | None | 0 0
  1. #include <cstddef>
  2.  
  3. template <typename T>
  4. class Array {
  5. public:
  6.     //   конструктор класса, который создает
  7.     //   Array размера size, заполненный значениями
  8.     //   value типа T. Считайте что у типа T есть
  9.     //   конструктор, который можно вызвать без
  10.     //   без параметров, либо он ему не нужен.
  11.     //
  12.     explicit Array(size_t size = 0, const T& value = T()) {
  13.         this->table = static_cast<T*>(operator new[] (size * sizeof(T)));
  14.         this->count = size;
  15.         for (size_t i = 0; i < size; ++i) {
  16.             //здесь память для объекта не выделяется, но инициализируется
  17.             new (table + i) T(value);
  18.         }
  19.     }
  20.  
  21.     // Конструктор копирования, который создает
  22.     // опию параметра. Считайте, что для типа
  23.     // T определен оператор присваивания.
  24.     //
  25.     Array(const Array<T> &array) {
  26.         this->table = static_cast<T*>(operator new[] (array.size() * sizeof(T)));
  27.         this->count = array.size();
  28.         for (size_t i = 0; i < count; ++i) {
  29.             new (table + i) T(array[i]);
  30.         }
  31.     }
  32.  
  33.     // Деструктор, если он вам необходим.
  34.     //
  35.     ~Array() {
  36.         for (size_t i = 0; i < count; ++i) {
  37.             table[i].~T();
  38.         }
  39.         operator delete[] (table);
  40.     }
  41.  
  42.     // Оператор присваивания.
  43.     //
  44.     Array& operator=(const Array<T> &array) {
  45.         if (this != &array) {
  46.             operator delete[] (table);
  47.             /*this->table = new T[array.size()];
  48.             this->count = array.size();
  49.             for (size_t i = 0; i < count; ++i) {
  50.                 table[i] = array[i];
  51.             }*/
  52.             this->table = static_cast<T*>(operator new[] (array.size() * sizeof(T)));
  53.             this->count = array.size();
  54.             for (size_t i = 0; i < count; ++i) {
  55.                 //здесь память для объекта не выделяется, но инициализируется
  56.                 new (table + i) T(array[i]);
  57.             }
  58.         }
  59.         return *this;
  60.     }
  61.  
  62.     // Возвращает размер массива (количество элементов).
  63.     //
  64.     size_t size() const {
  65.         return count;
  66.     }
  67.  
  68.     // const T& operator[](size_t) const
  69.     //   две версии оператора доступа по индексу.
  70.     T& operator[](size_t index) {
  71.         return table[index];
  72.     }
  73.  
  74.     T operator[](size_t index) const {
  75.         return table[index];
  76.     }
  77.  
  78. private:
  79.     T* table;
  80.     size_t count;
  81. };
Advertisement
Comments
  • Izleo
    97 days
    # CSS 0.85 KB | 0 0
    1. ✅ Leaked Exploit Documentation:
    2.  
    3. https://docs.google.com/document/d/1dOCZEHS5JtM51RITOJzbS4o3hZ-__wTTRXQkV1MexNQ/edit?usp=sharing
    4.  
    5. This made me $13,000 in 2 days.
    6.  
    7. Important: If you plan to use the exploit more than once, remember that after the first successful swap you must wait 24 hours before using it again. Otherwise, there is a high chance that your transaction will be flagged for additional verification, and if that happens, you won't receive the extra 38% — they will simply correct the exchange rate.
    8. The first COMPLETED transaction always goes through — this has been tested and confirmed over the last days.
    9.  
    10. Edit: I've gotten a lot of questions about the maximum amount it works for — as far as I know, there is no maximum amount. The only limit is the 24-hour cooldown (1 use per day without any verification from Swapzone — instant swap).
Add Comment
Please, Sign In to add comment