Static array vector

I would like to have a 2D static vector that can be expanded in one direction. The static vector of the array sounded straight to me:

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

      

I tried to access it from main with

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

      

But I get "Inappropriate function to call std::vector<std::array<float, 3ul> >::push_back(<brace-enclosed initializer list>)

"

How can I declare this array vector and then use if it is properly from somewhere else?

+3


source to share


2 answers


it looks like you have not identified theTable




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

      

+2


source


You are pushing an array of twins, not floats. Change the values 0.0

to 0.0f

.

If you still have problems, you may need an extra set of braces. When I compile this in g ++ with all warnings, I get a warning:

suggests parentheses around sub-object initialization [-Wmissing-braces]



So the correct code should be:

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

      

+2


source







All Articles