2

I get this warning for these two lines of code:

 const int entityNumber = materialNames.size();
 SceneNode* nodes[entityNumber];

I thought declaring entityNumber as const would fix this. (It did in a previous version when entity number was just a value I set myself) however it doesn't appear that this works. As you can tell I am quite new to c++, so sorry if this is a stupid question.

1
  • 1
    If materialNames.size() can't be determined at compile-time, then the compiler can't preallocate the memory for the array. Commented Mar 29, 2013 at 21:56

2 Answers 2

2

You should probably make a std::vector, which is a dynamic-length array, but with a lot of support for common operations:

// This reserves space for all the nodes you'll store
std::vector<SceneNode> nodes(materialNames.size());
Sign up to request clarification or add additional context in comments.

Comments

1

Use std::vector instead of legacy arrays.

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.