Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

missing subscript c++

Tags:

c++

subscript

right now c++ is giving me this error: error C2087 'color' missing subscript first time i get this and i dont know what to do >.< hope any1 can help me

struct Color{
    float r;
    float g;
    float b;
};
Color color[][];

and im using it here

for(int i=0;i<cubes;i++)
{
    color[i][0].r = fRand();color[i][0].g=fRand(.5);color[i][0].b=fRand();

...etc

like image 392
Makenshi Avatar asked Jan 22 '26 04:01

Makenshi


2 Answers

You are trying to create an array without specifying its size. If the size is dynamic, you should use pointers instead. type x[][]; is always an error, regardless of type. You can initialize your array though, int x[] = {10,11}; // ok or int[][2]={{1,2},{1,2},{1,3}}; // also works

like image 167
a1ex07 Avatar answered Jan 24 '26 23:01

a1ex07


You should specify the size of your array:

Color color[HEIGHT][WIDTH];
like image 22
Phong Avatar answered Jan 24 '26 22:01

Phong



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!