因此,这是我遇到的一项任务。分配的基础是具有一组字符串保留区域。这些区域中有事故,我们必须显示一个区域中的事故数量,该区域的计数保存在并行数组中。我以后可以做的显示部分,但是,我得到的错误是:
LNK1120: 1 unresolved externals
LNK2019: unresolved external symbol "void __cdecl findLowest(int,int,class
std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)"
(?findLowest@@YAXHHV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)
referenced in function _main
最后一个错误是非编译错误,表示此文件不是有效文件或不存在。
我提供了指向作业全部内容的链接,因为说明太长了,无法全部写出来。
https://mega.co.nz/#!INQjXbiS!lYbQ4gBHmsPua1wv1aigeZ_6MqIxvor7YPCFv49-G0Q
谢谢你的帮助!
#include <stdafx.h>
#include <string>
#include <iostream>
using namespace std;
//Function prototypes
void findLowest(int, int, string);
int getNumAccidents(string);
int main(){
const int NUM_REGIONS = 5;
string regionNames[NUM_REGIONS] = { "North", "South", "East", "West", "Central" };
int regionAccidents[NUM_REGIONS];
for (int i = 0; i < NUM_REGIONS; i++){//Populates the accident array
regionAccidents[i] = getNumAccidents(regionNames[i]);
if (regionAccidents[i] < 0)//checks to see if there are any accidents counts lower than 0
regionAccidents[i] = 0;
findLowest(regionAccidents[i], NUM_REGIONS, regionNames[i]);
}
}
int getNumAccidents(string region){
return 5;
}
void findLowest(int regAccidents[], int arraySize, string regNames[]){
int lowest = 0;
for (int i = 0; i <= arraySize; i++){
if (regAccidents[i] < regAccidents[i++])
lowest = regAccidents[i++];
}
}
最佳答案
您将使用参数findLowest
声明函数(int, int, string)
,但稍后使用(int[], int, string[])
对其进行定义。从技术上讲,这些是不同的函数,因此链接器找不到所声明的函数。
只需将声明固定在文件顶部以匹配实际定义,即可正常工作。
关于c++ - C++无法解析的外部函数,编译错误和带有字符串的数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22459835/