Hi guys

I'm new to c++/openGL (used java a lot more) and have run into an issue while trying to write a program using an array.
I have declared the array as GLfloat in the header file and then initialized it with a bunch of values in the constructor of the .cpp file. I keep getting an error so here is my code as well as the error i receive when compiling:

tetromino.cpp:17: error: ‘vertices’ was not declared in this scope
tetromino.cpp:17: error: expected primary-expression before ‘]’ token


GLfloat vertices[ ][3];

tetromino.cpp: (inside constructo)

initialX = 1.0;
initialY = 1.0;
initialZ = 1.0;

vertices[ ][3] = {{-initialX,-initialY,initialZ},{-initialX,initialY,initialZ},{initialX,initialY,initialZ},

Any sort of help as to how to fix this issue would be greatly appreciated. I have use this same array but when only using one .cpp file, no header and it worked fine but now i keep getting this error an im not sure how to fix it. Also if i use static in the declaration of the array in the header file i get rid of the first error and am left with this error:
tetromino.cpp:17: error: expected primary-expression before ‘]’ token


That sort of statement will only work at array declaration.

int data[][3] = { {1,2,3}, {4,5,6} };

In your case, where the array is declared in the header, it must be given a size for both dimensions. Then, in the constructor, you must initialize it within loop(s).

for( r = 0; r < 2; r++ )
   for( c = 0; c < 3; c++ )
       data[r][c] = initvalue;

If your problem is one where you don't know the number of vertices at compile time, you should consider using STL vector, which easily allows increasing size as you add elements. Otherwise, you'll have to use dynamic memory allocation, which the vector does for you.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.