Construct with a literal array
Hi. I'm trying to initialise an array in a constructor. I know I can do it like the following:
1 2 3 4 5
|
double* data;
data = new double[9];
data[0] = 1;
data[1] = 0;
// . . .
|
What I would really like to do is something like this:
1 2 3 4
|
double* data;
data = (double*){ 1, 0, 0,
0, 1, 0,
0, 0, 1 };
|
But this code gives me an error:
error: expected primary-expression before ‘{’ token
|
Is there a way to write clean code that is more like the second block of code?
well, i'm not %100 sure but i guess {} are used only for initialization with decleration.
Like;
1 2 3
|
double data[9] = { 1, 0, 0,
0, 1, 0,
0, 0, 1 };
|
Last edited on
Topic archived. No new replies allowed.