声明静态字符串变量的正确方法如何?如果我编译以下程序,clang会给我一些警告。
#include<string>
class foo {
public:
static std::string bar;
};
std::string foo::bar;
int main()
{
foo::bar = "test";
}
输出:
test.cpp:8:18: warning: declaration requires a global constructor [-Wglobal-constructors]
std::string foo::bar;
^~~
test.cpp:8:18: warning: declaration requires an exit-time destructor [-Wexit-time-destructors]
test.cpp:8:18: warning: declaration requires a global destructor [-Wglobal-constructors]
我打电话给&#34; clang ++ test.cpp -o test -Weverything&#34;如果栏是例如,我不会收到任何警告一个int。