Skip to main content
GameDev.net gamedev.net
🔒 Locked

Yet another stupid error.

Started by Galileo430 Dec 12, 2000 at 10:40 PM 1 replies 450+ views
Original Post
Galileo430
Galileo430
Just when I get my program back and running. I code in the matrix manipulation part of it and I get this stupid error. Here is the line and the error...
  
ColorMatrix = new (unsigned char[hColorMap.sizex][hColorMap.sizey]);

error C2540: nonconstant expression as array bound
  
Anyone bumped into this before? I make a stupid error? I looked over K&R, can''t figure it out.
------------------------------------------------------------I wrote the best video game ever, then I woke up...
Dragonskin
Dragonskin
As far as I understand, you can''t allocate multi-dimensional arrays. You have to have the first one be a static array size, and then you can allocate the second.
Quantum
Quantum
I think this should do it for you:

  
unsigned char **ColorMatrix;

//...


ColorMatrix = new unsigned char *[hColorMap.sizex];
for(DWORD i = 0; i < hColorMap.sizex; i++)
ColorMatrix<i> = new unsigned char[hColorMap.sizey];

//And to delete:

for(DWORD i = 0; i < hColorMap.sizey; i++)
delete [] ColorMatrix[i];

delete [] ColorMatrix;



I havn''t tested that, but I think it should work

Topic Locked

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

Sign in to reply to this topic.