/
spirzen
/
it-code-examples
Обзор
Документация
Войти
/
spirzen
/
it-code-examples
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
examples/cpp/cpp-506-14-013/main.cpp
45 строк
1 KB
Spirzen
Code migration pack
09 июн 2026, 01:41
09 июн 2026, 01:41
cebc284
Код
Авторство
О чём код?
class GoodBuffer { int* data = nullptr; size_t size = 0; public: GoodBuffer(size_t n) : size(n), data(new int[n]) {} // Конструктор копирования GoodBuffer(const GoodBuffer& other) : size(other.size), data(new int[other.size]) { std::copy(other.data, other.data + other.size, data); } // Оператор присваивания копированием GoodBuffer& operator=(const GoodBuffer& other) { if (this != &other) { delete[] data; size = other.size; data = new int[size]; std::copy(other.data, other.data + other.size, data); } return *this; } // Конструктор перемещения GoodBuffer(GoodBuffer&& other) noexcept : size(other.size), data(other.data) { other.size = 0; other.data = nullptr; } // Оператор присваивания перемещением GoodBuffer& operator=(GoodBuffer&& other) noexcept { if (this != &other) { delete[] data; size = other.size; data = other.data; other.size = 0; other.data = nullptr; } return *this; } ~GoodBuffer() { delete[] data; } };