der*_*khh 1 c++ static initialization vector c++11
如果我想在类中初始化向量,例如:
class A {
private:
static std::vector<double> label_map;
};
Run Code Online (Sandbox Code Playgroud)
如果我想初始化这个静态向量,最好的方法是什么?我在其他一些帖子中读过,从GCC 4.4开始,它支持C++ 0x中的新功能,我们可以直接使用
static std::vector<double> label_map = {1, 2, 3, 4};
Run Code Online (Sandbox Code Playgroud)
但似乎它对我不起作用.
所以...结束:
// thefile.cpp
class Foo
{
static std::vector<int> v;
};
std::vector<int> Foo::v { 1, 2, 3, 4 };
Run Code Online (Sandbox Code Playgroud)
编译g++ -std=c++0x -c -o thefile.o thefile.cpp # ....