expected unqualified-id before '{'
我的代码哪里有这个错误?谢谢大家!
#include <iostream>
using std::cout;
using std::endl;
//function prototypes
void findsmallest (int[], int &);
void findsmallest (int scores [], int & min);
int main()
{
//declare variables
int smallest = 0;
int scores[20] = { 90, 54, 23, 75, 67,
89, 99, 100, 34, 99,
97, 76, 73, 72, 56,
73, 72, 65, 86, 90 };
findsmallest(scores, smallest);
return 0;
//call function find smallest
findsmallest (scores, smallest);
cout << "Minimum value in the array is " << smallest << endl;
system ("pause");
return 0;
}
//function definition
void findsmallest(int scores [], int & min);
{
min = scores[0];
int i;
for(i = 0; i < 20; i++)
{
if(scores[i] < min)
{
min = scores[i];
}
}
}
//end display findsmallest
system ("pause");
return 0;
最佳答案
错误在 findsmallest()
函数定义的第一行。去掉分号,它应该可以工作(除非代码中有其他错误——我没有检查它的正确性)。
void findsmallest(int scores [], int & min); <-------semicolon
{
对比
void findsmallest(int scores [], int & min) <--------no semicolon
{
错误告诉您分号后面的左大括号 ({
) 缺少前面的类/结构/union/函数声明,因此编译器不知道如何处理它。删除分号,现在编译器知道它是函数定义的主体。
关于c++ - 只是想知道此错误消息的真正含义!,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1719055/