Skip to content

Commit

Permalink
refactor: 使用 fopen 而非 open_file
Browse files Browse the repository at this point in the history
  • Loading branch information
FeignClaims authored Sep 23, 2024
1 parent e6ea315 commit 1fc9d7b
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions faq/rule_of_350/main.rst
Original file line number Diff line number Diff line change
Expand Up @@ -158,18 +158,20 @@ rule of 3/5/0: 要么不定义任何特殊函数, 要么定义它们全部
.. code-block:: cpp
:linenos:
#include <cstdio>
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
Expand Down

0 comments on commit 1fc9d7b

Please sign in to comment.