xcrypt
xcrypt

Reputation: 3376

Error: argument of type " float(*)[1] " is incompatible with parameter of type " float** "

I have a function with the following signature:

float* Interpolate(float t, UINT iOrder, UINT iDimension, float** ppPointsArray);

When trying to call it as follows:

float ppfValues[2][1];
ppfValues[0][0] = 0.0f;
ppfValues[1][0] = 10.0f;

float* pfResult = MyMathFuncs::Interpolate(0.5f,2,1,ppfValues);

I get the following error:

Error: argument of type float(*)[1] is incompatible with parameter of type "float**"

If I want to call it properly, I should do it like this:

float** ppfValues = new float*[2];
ppfValues[0] = new float(0.0f);
ppfValues[1] = new float(10.0f);

float* pfResult = MyMathFuncs::Interpolate(0.5f,2,1,ppfValues);

Now the question is: I thought float[x][y] was actually the same as a float** Why are they not? What are the technical reasons? And what are they exactly, then?

Upvotes: 2

Views: 6595

Answers (1)

cnicutar
cnicutar

Reputation: 182639

I thought float[x][y] was actually the same as a float**

It all boils down to the fact that arrays and pointers aren't equivalent. Below is a list of C FAQs (even if this is a C++ question) which stress this fact in various ways.

Upvotes: 7

Related Questions