数组的静态向量

Static vector of array

我想要一个可以在一个方向上延伸的二维静态矢量。数组的静态向量听起来很对我:

struct A
{
    public:
        static std::vector<std::array<float, 3> > theTable;
};

我尝试通过以下方式从 main 访问它:

A::theTable.push_back({0.0, 0.0, 0.0});

但是我得到了"no matching function for call to std::vector<std::array<float, 3ul> >::push_back(<brace-enclosed initializer list>)"

我如何声明这个数组向量,然后从其他任何地方正确使用它?

您推的是双精度数组,而不是浮点数。将 0.0 值更改为 0.0f.

如果您仍然有问题,可能是您需要一副额外的牙套。当我在 G++ 中编译所有警告时,我收到警告:

suggest braces around initialization of subobject [-Wmissing-braces]

所以,正确的代码应该是:

A::theTable.push_back({{0.0f, 0.0f, 0.0f}});

你好像还没有定义theTable


struct A
{
    public:
        static std::vector<std::array<float, 3> > theTable;
};
std::vector<std::array<float, 3> > A::theTable; //define