这个问题不太可能帮助任何 future 的访客;它只与一个小地理区域、一个特定时刻或一个非常狭窄的情况相关,而这些情况通常不适用于互联网的全局受众。如需帮助使这个问题更广泛地适用,visit the help center .
9年前关闭。
我正在尝试编译一些程序的 C++ 代码,该程序将使用函数计算 10 个整数的平均值。
除了一个错误,我什么都做对了:
error LNK2019: unresolved external symbol "int __cdecl sumFunc(int)" (?sumFunc@@YAHH@Z) referenced in function _main
谁能指出我修复此代码的正确方向,以便我可以编译它?谢谢
#include <iostream>
#include <conio.h>
#include <cmath>
using namespace std;
int sumFunc (int);
double averageFunc (double&);
int const size = 10;
int main()
{
int integer = 0;
double average;
cout << "Enter ten numbers: ";
sumFunc(integer);
averageFunc(average);
cout << "The average is " << average << endl;
getch();
return 0;
}
int sumFunc(int integer[])
{
int sum = 0;
for (int index = 0; index < size; index++)
{
cin >> integer[index];
sum = sum + integer[index];
}
return sum;
}
double averageFunc(double& average)
{
int sum = 0;
for (int index = 0; index < size; index++)
{
average = sum / 10.0;
}
return average;
}
最佳答案
你的函数原型(prototype)int sumFunc (int);
与函数声明不匹配int sumFunc(int integer[])
关于c++ - 编译器错误 : 1 unresolved external,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16493338/