I have two questions about arrays.
1) I created an array with [][] and passed it into a function expecting **. I got an error saying: cannot convert parameter 1 from 'gfx::Vec3f [800][600]' to 'gfx::Vec3f **. I thought [][] and ** are the same thing!
2) I tried doing "Vec3f image[width][height];" before, but the compiler complained saying "expected constant expression". So I changed it to "Vec3f image[800][600];" to make it compile. Why must I do this hardcoding?
[cpp]
Pixels:
ixels(Vec3f** colors, int width, int height)
{
this->width = width;
this->height = height;
this->image = colors;
}
[/cpp]
[cpp]
int width = 800;
int height = 600;
Vec3f image[800][600];
for(int w = 0; w < width; w++)
for(int h = 0; h < height; h++)
image[w][h] = Vec3f(w / width, h / height, w / height);
Pixels pixels = new Pixels(image, width, height);
[/cpp]
1) I created an array with [][] and passed it into a function expecting **. I got an error saying: cannot convert parameter 1 from 'gfx::Vec3f [800][600]' to 'gfx::Vec3f **. I thought [][] and ** are the same thing!
2) I tried doing "Vec3f image[width][height];" before, but the compiler complained saying "expected constant expression". So I changed it to "Vec3f image[800][600];" to make it compile. Why must I do this hardcoding?
[cpp]
Pixels:
{
this->width = width;
this->height = height;
this->image = colors;
}
[/cpp]
[cpp]
int width = 800;
int height = 600;
Vec3f image[800][600];
for(int w = 0; w < width; w++)
for(int h = 0; h < height; h++)
image[w][h] = Vec3f(w / width, h / height, w / height);
Pixels pixels = new Pixels(image, width, height);
[/cpp]