在类中初始化静态向量最方便的方法是什么?
What is the most convenient way to initialize a static vector inside a class?
如果我想在类中初始化一个向量,例如:
class A {
private:
static std::vector<double> label_map;
};
如果我想初始化这个静态向量,最好的方法是什么?我在其他一些帖子中读到,从GCC 4.4开始,它支持c++ 0x的新功能,我们可以直接使用
static std::vector<double> label_map = {1, 2, 3, 4};
然而,它似乎不适合我
所以…包装:
// thefile.cpp
class Foo
{
static std::vector<int> v;
};
std::vector<int> Foo::v { 1, 2, 3, 4 };
用g++ -std=c++0x -c -o thefile.o thefile.cpp # ...
编译
相关文章:
- 为不同配置设置MSVC_RUNTIME_LIBRARY的正确方法是什么
- 通过方法访问结构
- 最小硬币更换问题(自上而下方法)
- C++为构建时间获取QDateTime的可靠方法
- 在C#中处理C++指针而不使用unsafe的最佳方法
- 处理多个异常集合的C++方法
- 当使用Lua作为嵌入式语言(比如c++)时,有什么简单/方便的方法可以找到变量在Lua中的定义位置吗
- C++/V8调用非静态函数/创建临时实例的方便方法
- 有没有一种方便的方法可以从属性树中删除节点,同时保留其子节点
- 为具有一个数字数据成员的类定义所有比较运算符的方便方法
- 有没有一种方便的方法可以让unique_ptr自动拥有像shared_ptr这样的deleter
- 有没有一种方便的方法可以通过一些Qt小部件只输入一个字符
- 用静态2d数组定义类的方便方法是什么(并且2d数组的大小只有在编译时才知道)
- 将格式化数据转换为结构的方便方法
- 在类中初始化静态向量最方便的方法是什么?
- 查找变量声明的方便方法
- 有没有一种在C++中初始化简单结构的方便方法
- 最方便的表示向量引用的向量的方法
- 方便的类型推断方法,用新对象重新分配' unique_ptr '值
- 是否有任何(方便的)方法可以在 C++11 "foreach"语句中检索当前迭代 #?