Multidimentional array

Hey,

I know you can assign values to a mutidimensional array this way:
1
2
3
4
5
int numbers[2][3] = 
{
{1, 2, 3},
{2, 3, 4},
};


The declaration of my array in done in my class:
private:
int numbers[2][3];

Now I would like to assign the values row per row in my constructor, but this is not possible:
numbers[0][] = {1, 3, 4};

Is there a way to do this? I know I can likely assign these when declaring array, but as the numbers got calculated in the constructor, I have to do it this way.

Thanks
Last edited on
Try numbers[0]={1,2,3};
Nope :(

error C2059: syntax error : '{'
error C2143: syntax error : missing ';' before '{'
error C2143: syntax error : missing ';' before '}'
Maybe I'm wrong, but I believe it has to be accomplished with a loop. Place new column data into a new 1d array and iterate through the individual positions, copying into 2nd row of 2d array.
1
2
3
4
5
6
//For replacing only 2nd row
int newCol[3]={1,2,3};
        for (int col=0; col<3; col++) {
            int row=1;
            numbers[row][col] = newCol[col];
        }
So you really have to assign them one by one?

Ok, thanks :)
Topic archived. No new replies allowed.