Assigning to a 2d array with braces

I know for a 2d initialisation you can do this:

 
int mda [3][3]={ {1,2,3},{4,5,6},{7,8,9} };


but how do I do this:
1
2
3
int mda [3][3];
mda = { {1,2,3},{4,5,6},{7,8,9} };


Is it possible to do this in C++11?
Is there a reason you would seperate the lines? :3
I mean, if you want to assign the values, why do it later when you can do it now? :3
Since you are assigning by hand anyway:

1
2
3
4
5
6
7
8
9
10
11
12
13
int** mda = new int*[3];

for (unsigned int i = 0; i < 3; i++)
{
    mda[i] = new int[3];
}
for (unsigned int x = 0; x < 3; x++)
{
    for (unsigned int y = 0; y < 3; y++)
    {
        mda[x][y] = 1 + y + 3 * x;
    }
}


Assignment lists don't work outside of initialization.

http://cboard.cprogramming.com/cplusplus-programming/136721-brace-enclosed-initializer-list-assignment.html

seems to imply that it is possible on more modern compilers. You should check it out.
Last edited on
@Guardian Angel

Because I want to declare in one function and assign in another?
Topic archived. No new replies allowed.