Unnamed Namespaces Replace File Statics

C++ Primer 4/e在Namespaces这个地方有一段说明:‘Prior to the introduction of namespaces in standard C++, programs had to declare names as static to make them local to a file. The use of file statics is inherited from C. In C, a global entity declared static is invisible outside the file in which it is declared.

警告

The use of file static declarations is deprecated by the C++ standard. A deprecated feature is one that may not be supported in future releases. File statics should be avoided and unnamed namespaces used instead.’

中文版的这样写:‘标准C++引入namespace之前,程式必须将某个名称宣告为static才能使它区域化(local to)于档案内。这种性质继承自C语言。在C语言中,宣告为static的global物体,在其所处档案之外是不可见的。

警告

C++不赞成使用file static变数宣告。这意味C++将来有可能不再支援此一特性。’

还好我static也很少用。