關于匿名命名空間 與 const修飾的全局變量在作用域方面的問題
//?a.cpp int?foo?=?111;
//?b.cpp extern?int?foo; cout?<<?foo?<<?endl;
- 如上,foo 輸出 111
//?a.cpp const?int?foo?=?111;
//?b.cpp extern?const?int?foo; cout?<<?foo?<<?endl;
- 如上,編譯錯誤,因為 const 修飾的變量默認非外部變量
- 所以,const 修飾的變量有沒有必要通過使用 static 修飾的方法或匿名命名空間約束的方法,限制其不暴露給其他編譯單元呢?
2020-12-23
我不知道