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也很少用。

感謝你看到這裡,很快就可以離開了,但最好的獎勵行動就是按一下幫我分享或留言,感恩喔~

點我分享到Facebook

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *