c++ - C++无法解析的外部函数,编译错误和带有字符串的数组

标签 c++ string function parameters

因此,这是我遇到的一项任务。分配的基础是具有一组字符串保留区域。这些区域中有事故,我们必须显示一个区域中的事故数量,该区域的计数保存在并行数组中。我以后可以做的显示部分,但是,我得到的错误是:

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/

相关文章:

c++ - 让编译器在编译前推断出函数的参数

c++ - 在 C++ (g++) 中使用 errno 作为异常参数的意外控制流(编译器错误?)

C++从内部销毁结构

ios - 尝试用 replaceOccurrencesOfString :withString:options:range: 改变不可变对象(immutable对象)

c++ - error 4430 : missing type specifier - int assumed. 注意:C++不支持default-int

C++ 的 std::string 池,调试版本? std::string 和 valgrind 问题

c++ - C++ 中的模板函数?也许不是正确的术语

javascript - Onkeydown JS函数添加调用相同函数的输入

c++ - 既然可以使用默认的TimerQueue,为什么还要使用自己的TimerQueue?

c#递归函数并非所有代码路径都返回一个值