-4

A function I want to use requires an input of a float ** array.

How can i initialize this to be a 2x2 array?

Just using float[2][2] = {{0,100},{0,200}} obviously doesn´t work.

I also tried

float** ranges = new float*[2];
ranges[0] = {0,100};
ranges[1] = {0,200};
Eumel
  • 1,298
  • 1
  • 9
  • 19

1 Answers1

0
float** ranges = new float*[2];
ranges[0] = {0,100};
ranges[1] = {0,200};

doesn't work since:

  1. The RHS is an initilaization list that cannot be assigned to a pointer.
  2. range[0] and range[1] are pointers for which memory needs to be allocated first. And then, you can assign values to individual elements.

You can use:

ranges[0] = new float[2]{0,100};
ranges[1] = new float[2]{0,200};

or

ranges[0] = new float[2];
ranges[0][0] = 0;
ranges[0][1] = 100;
ranges[1] = new float[2];
ranges[1][0] = 0;
ranges[1][1] = 200;

Of course, make sure to add code to delete them.

R Sahu
  • 204,454
  • 14
  • 159
  • 270