Skip to main content
gamedev.net
🔒 Locked

C++ Win32 array problem

Started by GameDev.net Jun 19, 2010 at 6:38 AM 6 replies 1.8k views
Original Post
GameDev.net
GameDev.net
Hi im working in C++ and i have run into a problem

short indices[(width-1)*(length-1)*6];

Error 6 error C2133: 'indices' : unknown size


Any help? Thanks:)
rip-off
rip-off
Array sizes must be known at compile time. You can use a container like std::vector<> instead, it acts like an array:
#include <vector>std::vector<short> indices((width - 1) * (length - 1) * 6);
matrisking
matrisking
Also worth noting that if you'd rather use arrays than vectors for some reason, then you can make the "width" and "length" const. This will make the values of these variables known at compile time, meeting the requirement rip-off mentioned.
mrchrismnh
mrchrismnh
short* indices = new short[dim];

I like to keep things clean as possible in array brackets even if it means creating a new variable.
"It's like naming him Asskicker Monstertrucktits O'Ninja" -Khaiy

rip-off
rip-off
I would avoid using raw new[] / delete[] unless you have an extremely compelling reason. For most use cases, std::vector<> could be considered a superior drop-in replacement for dynamic array allocation/deletion.
rip-off
rip-off
The "const" keyword doesn't necessarily imply the compile time constant which would be necessary for an array dimension. If the data is loaded from a file, you could mark the values as const but you still won't be able to use them to dimension an array.
Ferneu
Ferneu
Quote:
Original post by rip-off
The "const" keyword doesn't necessarily imply the compile time constant which would be necessary for an array dimension. If the data is loaded from a file, you could mark the values as const but you still won't be able to use them to dimension an array.


That is probably why he said to "declare const values" instead of "use the keyword const". Those are two different things. You point is completely valid though.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.