3

I would like to have a 2D static vector that can be extended in one direction. A static vector of array sounded right 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 "no matching function for call to std::vector<std::array<float, 3ul> >::push_back(<brace-enclosed initializer list>)"

How can I declare this vector of array and then use if properly from anywhere else?

2 Answers 2

2

it looks like you have not defined theTable


struct A
{
    public:
        static std::vector<std::array<float, 3> > theTable;
};
std::vector<std::array<float, 3> > A::theTable; //define 
Sign up to request clarification or add additional context in comments.

1 Comment

Indeed that was needed. But I also need paddy's answer to get it to work!
2

You're pushing an array of doubles, not floats. Change the 0.0 values to 0.0f.

If you still have issues, it might be that you need an extra set of braces. When I compile that in G++ with all warnings, I get the warning:

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

So, the correct code should be:

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.