我的 DEV C++ IDE 不断给我消息:"Id returned 1 exit status" 和 "Undefined reference to "function(int, int)”。如何解决?

My DEV C++ IDE continously gives me the message:"Id returned 1 exit status" and "Undefined reference to "function(int, int)". How to fix it?

这是我的代码

#include <stdio.h>
#include <conio.h>

int func(int , int);
main(){
int m[3][3]={(0,0,0),
             (0,0,0),
             (0,0,1)};
int n=3,a;
a=func(m[3][3], n);
if(a==1) printf("True");
else printf ("False");
getch();
}

int func(int m[3][3], int n)
{
int i, j, k=0;
for (i=0;i<n;i++)
    for (j=0;j<n;j++)
        if(m[i][j]==1) k=1;

    return k;

}

我错在哪里了? IDE 的消息是: Funk.cpp:(.text+0x4b): 未定义对`func(int, int)'的引用 [错误] ld 返回 1 退出状态

func 的函数原型和定义不匹配。因此错误。通过将函数原型更改为

来修复它
int func(int[3][3], int);

下一个错误是:

a=func(m[3][3], n);

应该改为

a=func(m, n);

因为你想传递数组,而不是数组之外的无效内存位置。


而且我认为你想要

int m[3][3]={{0,0,0},
             {0,0,0},
             {0,0,1}};

而不是

int m[3][3]={(0,0,0),
             (0,0,0),
             (0,0,1)};

此外,最好使用main的标准定义,即更改

main(){

int main(void) {

链接器期待 int func(int, int); 定义 ,但您没有提供。

您正在 a=func(m[3][3], n);

行中调用该函数

源代码末尾的函数 func 参数类型错误。您显然正在使用 C++ 编译器(您是要这样做吗?)因为函数 重载 在 C.

中不受支持