diff --git a/Chapter13/lfs_raii/app/src/main_lfs_raii.cpp b/Chapter13/lfs_raii/app/src/main_lfs_raii.cpp index 3107495..e895bf7 100644 --- a/Chapter13/lfs_raii/app/src/main_lfs_raii.cpp +++ b/Chapter13/lfs_raii/app/src/main_lfs_raii.cpp @@ -16,6 +16,8 @@ namespace fs{ struct lfs { + lfs() = delete; + static inline lfs_t fs_lfs; static void init() { @@ -33,8 +35,10 @@ public: } } ~file() { - printf("Closing file in destructor.\r\n"); - lfs_file_close(&lfs::fs_lfs, &file_); + if(is_open()) { + printf("Closing file in destructor.\r\n"); + lfs_file_close(&lfs::fs_lfs, &file_); + } } [[nodiscard]] bool is_open() const {