i'm trying to initialize an array of a class, but i can only do this if i specify every object of the array, for example:
class Pixel{
private:
int color;
public:
Pixel(int color):color(color){}
};
class Screen{
private:
Pixel screen[1920][1080];
public:
Screen(){
//code//
//i was trying to use for, to determinate each pixel color from a certain area
//but i cannot, bc i would have to do something like this:
screen[1920][1080] = {{Pixel(1),Pixel(1),Pixel(1),Pixel(1)...1080 times},{Pixel(2)
,Pixel(2), Pixel(2)...1080 times}...1918 times}
//as you can see, is nearly impossible to do this in this way.
}
};
there is a native way to initialize this array with fors or something like this?
(that code is just an EXAMPLE with the exact same logic, its not from my project)
Pixelclass. Or better yet just give the parameter in your ctor a default valuevectorinstead of an array.forloop (two nested, in fact) to assign initial values in the constructor