我收到了这些错误信息:
Error 1 error LNK2019: unresolved external symbol "public: void __thiscall ArrayIntStorage::sortOwn(void)" (?sortOwn@ArrayIntStorage@@QAEXXZ) referenced in function _main G:\08227\ACW\MAIN\08227_ACW2_Test_Harnesses_2010-11\C_Style_Array\main.obj C_Style_Array
Error 2 error LNK2019: unresolved external symbol "public: void __thiscall ArrayIntStorage::sortStd(void)" (?sortStd@ArrayIntStorage@@QAEXXZ) referenced in function _main G:\08227\ACW\MAIN\08227_ACW2_Test_Harnesses_2010-11\C_Style_Array\main.obj C_Style_Array
Error 3 error LNK2019: unresolved external symbol "class std::basic_ostream > & __cdecl operator<<(class std::basic_ostream > &,class ArrayIntStorage const &)" (??6@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@std@@AAV01@ABVArrayIntStorage@@@Z) referenced in function _main G:\08227\ACW\MAIN\08227_ACW2_Test_Harnesses_2010-11\C_Style_Array\main.obj C_Style_Array
Error 4 error LNK2019: unresolved external symbol "class std::basic_istream > & __cdecl operator>>(class std::basic_istream > &,class ArrayIntStorage &)" (??5@YAAAV?$basic_istream@DU?$char_traits@D@std@@@std@@AAV01@AAVArrayIntStorage@@@Z) referenced in function _main G:\08227\ACW\MAIN\08227_ACW2_Test_Harnesses_2010-11\C_Style_Array\main.obj C_Style_Array
Error 5 error LNK2019: unresolved external symbol "public: bool __thiscall ArrayIntStorage::setReadSort(bool)" (?setReadSort@ArrayIntStorage@@QAE_N_N@Z) referenced in function _main G:\08227\ACW\MAIN\08227_ACW2_Test_Harnesses_2010-11\C_Style_Array\main.obj C_Style_Array
Error 6 error LNK1120: 5 unresolved externals G:\08227\ACW\MAIN\08227_ACW2_Test_Harnesses_2010-11\C_Style_Array\Debug\C_Style_Array.exe 1 1 C_Style_Array
我不知道发生了什么,我想知道我是否错过了什么? 我是新手,它没有给我任何行号,所以我不确定给你哪个代码,所以我给你这部分
#include <fstream>
#include <iostream>
using namespace std;
#include "ArrayIntStorage.h"
int main(int argc, char **argv) {
ifstream fin1("ACW2_data.txt");
ofstream out1("1-arrayUnsortedRead.txt");
ofstream out2("2-arrayUnsortedRead-thenSTDSort.txt");
if(!fin1.is_open())
{
cout << "FAIL" << endl;
return 1;
}
ArrayIntStorage arrayStorage1;
arrayStorage1.setReadSort(false); // do not read sort
// read in int values into data structure
fin1 >> arrayStorage1;
// output int values in data structure to file
out1 << arrayStorage1;
// sort data structure using std
arrayStorage1.sortStd();
// output int values in data structure to file
out2 << arrayStorage1;
fin1.close();
out1.close();
out2.close();
最佳答案
您的链接器(编译器的一部分)无法找到 ArrayIntStorage::sortOwn()
的定义位置。
这通常发生在:
ArrayIntStorage::sortOwn()
的定义在另一个 .c 文件中,您忘记告诉编译器(因此未编译),- ArrayIntStorage 是一个仅包含头文件的库(因此没有其他 .c 文件),在这种情况下,您可能忘记了实现函数
sortOwn()
,而只是声明了它。< - ArrayIntStorage 是一个尚未链接的外部库。 (正如 Tomalak Geretkal 所指出的,并按照 paxdiablo 规定的步骤解决)
如果两者都不是,或者您发现这些选项令人困惑,请发布头文件 ArrayIntStorage.h
和相应的 .c 文件(如果有的话)。
关于c++ - LNK2019错误c++未解析的外部符号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5730135/