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