/
spirzen
/
it-code-examples
Обзор
Документация
Войти
/
spirzen
/
it-code-examples
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
examples/cpp/cpp-506-19-001/main.cpp
27 строк
861 B
Spirzen
Code migration pack
09 июн 2026, 01:41
09 июн 2026, 01:41
cebc284
Код
Авторство
О чём код?
class FileHandle { FILE* fp = nullptr; public: explicit FileHandle(const char* name, const char* mode) : fp(std::fopen(name, mode)) { if (!fp) throw std::runtime_error("fopen failed"); } ~FileHandle() { if (fp) std::fclose(fp); } FILE* get() const { return fp; } // Запрещаем копирование (единственное владение) FileHandle(const FileHandle&) = delete; FileHandle& operator=(const FileHandle&) = delete; // Разрешаем перемещение FileHandle(FileHandle&& other) noexcept : fp(other.fp) { other.fp = nullptr; } FileHandle& operator=(FileHandle&& other) noexcept { if (this != &other) { if (fp) std::fclose(fp); fp = other.fp; other.fp = nullptr; } return *this; } };