Commit 8e8e093 1 parent 171aa8d commit 8e8e093 Copy full SHA for 8e8e093
File tree 4 files changed +11
-5
lines changed
4 files changed +11
-5
lines changed Original file line number Diff line number Diff line change @@ -301,9 +301,12 @@ <h3 id="_3">封装在类内部</h3>
301
301
Game() { ... }
302
302
303
303
public:
304
- inline static Game instance; // 如果定义在头文件中,需要 inline!
304
+ // inline static Game instance; // 虽然很爽,但不能这样写,因为 Game 在他的 }; 结束前都是不完整类型
305
+ static Game instance; // 非定义声明,就好比全局变量的 extern Game instance 一样,不需要是完整类型
305
306
};
306
307
308
+ inline Game Game::instance; // 如果定义在头文件中,需要 inline!
309
+
307
310
Game::instance.updatePlayers();
308
311
</ code > </ pre >
309
312
< ol start ="2 ">
Original file line number Diff line number Diff line change @@ -252,7 +252,7 @@ <h2 id="_1">前言</h2>
252
252
< blockquote >
253
253
< p > < img src ="./img/bulb.png " height ="30px " width ="auto " style ="margin: 0; border: none "/> 本书还在持续更新中……要追番的话,可以在 < a href ="https://github.com/parallel101/cppguidebook "> GitHub</ a > 点一下右上角的 “Watch” 按钮,每当小彭老师提交新 commit,GitHub 会向你发送一封电子邮件,提醒你小彭老师更新了。</ p >
254
254
</ blockquote >
255
- < p > 更新时间:2024年08月15日 08:13:31 (UTC+08:00)</ p >
255
+ < p > 更新时间:2024年08月15日 08:14:01 (UTC+08:00)</ p >
256
256
< h2 id ="_2 "> 格式约定</ h2 >
257
257
< blockquote >
258
258
< p > < img src ="./img/bulb.png " height ="30px " width ="auto " style ="margin: 0; border: none "/> 用这种颜色字体书写的内容是温馨提示</ p >
Original file line number Diff line number Diff line change @@ -353,7 +353,7 @@ <h2 id="index-_1">前言</h2>
353
353
<blockquote>
354
354
<p><img src="../img/bulb.png" height="30px" width="auto" style="margin: 0; border: none"/> 本书还在持续更新中……要追番的话,可以在 <a href="https://github.com/parallel101/cppguidebook">GitHub</a> 点一下右上角的 “Watch” 按钮,每当小彭老师提交新 commit,GitHub 会向你发送一封电子邮件,提醒你小彭老师更新了。</p>
355
355
</blockquote>
356
- <p>更新时间:2024年08月15日 08:13:31 (UTC+08:00)</p>
356
+ <p>更新时间:2024年08月15日 08:14:01 (UTC+08:00)</p>
357
357
<h2 id="index-_2">格式约定</h2>
358
358
<blockquote>
359
359
<p><img src="../img/bulb.png" height="30px" width="auto" style="margin: 0; border: none"/> 用这种颜色字体书写的内容是温馨提示</p>
@@ -10424,9 +10424,12 @@ <h3 id="design_gamedev-_3">封装在类内部</h3>
10424
10424
Game() { ... }
10425
10425
10426
10426
public:
10427
- inline static Game instance; // 如果定义在头文件中,需要 inline!
10427
+ // inline static Game instance; // 虽然很爽,但不能这样写,因为 Game 在他的 }; 结束前都是不完整类型
10428
+ static Game instance; // 非定义声明,就好比全局变量的 extern Game instance 一样,不需要是完整类型
10428
10429
};
10429
10430
10431
+ inline Game Game::instance; // 如果定义在头文件中,需要 inline!
10432
+
10430
10433
Game::instance.updatePlayers();
10431
10434
</code></pre>
10432
10435
<ol start="2">
Load Diff Large diffs are not rendered by default.
You can’t perform that action at this time.
0 commit comments