c++ - 模拟模板的 C 错误

标签 c++ c dev-c++

我在 Dev C 中遇到此错误。它表示存在有关指针的错误,但我没有使用指针。

[Error] invalid conversion from 'int*' to 'int' [-fpermissive]

错误在这一行:

E=suma1 + distancias [x,y];

(其中 suma1E 是整数,distancias 是矩阵)

最佳答案

表达式x,y实际上是C和C++中的单个值。它评估xy,但给出您单个值y。如果您尝试的话,您可以看到它的实际效果:

#include <stdio.h>
int main (void) {
    int a;
    a = (1, 2, 3, 4, 5);
    printf ("%d\n", a);
    return 0;
}

将输出5

因此,当前正在评估的表达式 distancias [x,y] 是一个简单的 distancias [y] (因为评估 x这里没有副作用),这就是为什么它提示在需要 int 的地方使用 int pointer

多维数组的正确语法是 distancias [x][y]

关于c++ - 模拟模板的 C 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22187146/

相关文章:

c++ - 如何在不在主程序中时关闭程序

c++ - 使用指针实例化类

返回到帧数组时损坏的帧

c - 我的 c 程序打印 "out of memory"-error 但有很多可用的内存空间

openssl - OpenSSL 中的 PBKDF2 实现

c++ - vim 不高亮某些 c++ 关键字

c++ - 从已编译的可执行文件中获取编译器选项?

c++ - block 矩阵乘法

c - 如何使用 P 进程确定一个值是否存在于数组中

c++ - 在 Windows 7 中使用用于 Dev-C++ 的 cURL 库时遇到问题