从以下stackoverflow答案中,用户说:
It means that the variable is local to a translation unit (simply put, to a single source file), and cannot be accessed from outside it. This use of static is in fact deprecated in the current C++ Standard - instead you are supposed to use anonymous namespaces:
static int x = 0;
should be:
namespace { int x = 0; }
我并不反对使用匿名命名空间作为首选的方法,但是现在使用静态的确被弃用了吗?标准文件哪里说了这个?
static
不会以任何方式破坏其行为,除非警告方面的设置过于激进。现在正确的代码将继续保持正确。 - Pete Becker