我有一个具有以下签名的函数:
float* Interpolate(float t, UINT iOrder, UINT iDimension, float** ppPointsArray);
尝试按如下方式调用时:
float ppfValues[2][1];
ppfValues[0][0] = 0.0f;
ppfValues[1][0] = 10.0f;
float* pfResult = MyMathFuncs::Interpolate(0.5f,2,1,ppfValues);
我收到以下错误:
Error: argument of type float(*)[1] is incompatible with parameter of type "float**"
如果我想正确地调用它,我应该这样做:
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);
现在的问题是:我认为 float[x][y] 实际上与 float 相同** 他们为什么不呢?技术原因是什么?那么它们到底是什么?
最佳答案
I thought float[x][y] was actually the same as a float**
这一切都归结为数组和指针不等同。下面是 C 常见问题解答列表(即使这是一个 C++ 问题),它们以各种方式强调了这一事实。
- My compiler complained when I passed a two-dimensional array to a function expecting a pointer to a pointer.
- But I heard that char a[] was identical to char *a
- So what is meant by the ``equivalence of pointers and arrays'' in C?
- How do I write functions which accept two-dimensional arrays when the width is not known at compile time?
关于c++ - 错误 : argument of type "float(*)[1] " is incompatible with parameter of type "float** ",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7999647/