Original Post
I can''t figure something out, i.e. don''t know why I get this error.
I will explain what I''m doing:
I have a function
LoadTextures(char *textureFiles[],int numTextures)
This function I use to initialize the textures i.e. generate them with glGenTextures.
So what I need is an array of the form
GLUint textures[numTextures];
LoadTextures is called from the main Initialization function which is found in another file.
So VC++ gives me following error:
D:\Programming\NeHeGL\init.cpp(33) : error C2057: expected constant expression
D:\Programming\NeHeGL\init.cpp(33) : error C2466: cannot allocate an array of constant size 0
That is I can''t use the "int numTextures" for the length of the "textures" array. In fact, when I put a constant in it everything works fine. However, as I do not know the number of textures that will be loaded, I certainly can''t hard Code it.
So does anyone know why it does that.
For testing purposes I did the exact same thing with a very simple function and it worked
However, it doesn''t seem to work with my more complex code
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
void test(int i){
int j = 0;
int test[i];
for (j = 0; j<i;j++){
test[j] = j;
printf("%d\n", test[j]);
}
}
int main(int argc, char *argv[])
{
int i = 10;
test(i);
system("PAUSE");
return 0;
}