From 1fc9d7bc69956092f17e52d70518fdec437da0d7 Mon Sep 17 00:00:00 2001 From: FeignClaims Date: Mon, 23 Sep 2024 11:12:50 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E4=BD=BF=E7=94=A8=20fopen=20?= =?UTF-8?q?=E8=80=8C=E9=9D=9E=20open=5Ffile?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- faq/rule_of_350/main.rst | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/faq/rule_of_350/main.rst b/faq/rule_of_350/main.rst index 9e90eda5..4f298894 100644 --- a/faq/rule_of_350/main.rst +++ b/faq/rule_of_350/main.rst @@ -158,18 +158,20 @@ rule of 3/5/0: 要么不定义任何特殊函数, 要么定义它们全部 .. code-block:: cpp :linenos: + #include + class Widget { public: - Widget(std::string const& file_path) : file_(open_file(file_path)) {} - ~Widget() { close_file(file_); } + Widget(char const* file_path) : file_(fopen(file_path, "r")) {} + ~Widget() { fclose(file_); } private: - file* file_; + FILE* file_; }; int main() { - Widget widget(10); - } // widget 析构时调用 close_file 释放文件资源 + Widget widget("text.txt"); + } // widget 析构时调用 fclose 释放文件资源 .. admonition:: 相关核心准则 :class: coreguidelines