c++ - 错误 : argument of type "float(*)[1] " is incompatible with parameter of type "float** "

标签 c++ pointers

我有一个具有以下签名的函数:

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++ 问题),它们以各种方式强调了这一事实。

关于c++ - 错误 : argument of type "float(*)[1] " is incompatible with parameter of type "float** ",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7999647/

相关文章:

c++ - 传递动态分配的二维字符数组会导致段错误?

c - 在 C 中向字符串添加零

对 *char 的字符分配不起作用

c - 什么时候在 C 中未定义指针减法?

C++ ASIO : async_accept() handler throws exception when server destroys

c++ - OpenCV 项目无法编译

c++ - 使用 ffmpeg 流式传输自定义数据包的正确方法是什么?

c++ - 我们可以使用 pthread 库进行 opencv C++ 编程吗?

c++ - 按值和地址返回

python - Cython 中的矢量分配