當我編譯這個C程序,我得到一個錯誤:C++錯誤:「未定義參考CNT(INT)collect2:錯誤:LD返回1個退出狀態
In function `main': maxcount.cpp:(.text+0x63): undefined reference to `cnt(int)'
collect2: error: ld returned 1 exit status
是什麼意思這裏是代碼:
#include<iostream>
using namespace std;
int cnt(int);
int main()
{
int x[30],i,j,q;
cout<<"enter x[i]";
for(i=0;i<7;i++)
{
cin>>x[i];
}
q = cnt(x[30]);
}
int cnt(int x[30])
{
int i,j;
int max=x[0];
int count=0;
for(i=0;i<7;i++)
{
if(x[i]>max)
{
max=x[i];
}
else
{
max=x[0];
}
}
for(i=0;i<7;i++)
{
if(max==x[i])
{
count++;
}
}
cout<<count;
return 0;
}
你普遍錯誤地使用數組。它看起來像你認爲數組的名稱是'x [30]',但它不是;它的名字是'x'。 –