[C++筆記] 靜態變數(Static Storage Variable)
Published in
1 min readOct 29, 2018
(Global變數最好是有明確理由才使用)
一、介紹
Static關鍵字主要描述的是「可視範圍」和「變數週期」
Static Storage有三種使用方式
- Global Static 變數
- Local Static 變數
- Class Static變數
二、使用方法比較
1. Global 變數
Global Const Variable 跟 Static Const Variable是一樣的,Const的可視範圍就是同一個檔案內。
要讓其他檔案也能看到,就要加上Extern關鍵字。
define.cpp
main.cpp
2. Local Static 變數
1
2
3