我试图调用Dictionary类的成员函数来读取字典文件并将每个单词/定义放入对象数组(向量)中。当我在Dictionary的一个对象上调用loadDictionary()时,收到以下两个错误:
LNK2019 unresolved external symbol "public: void __thiscall Dictionary::loadDictionary(void)" (?loadDictionary@Dictionary@@QAEXXZ) referenced in function _main
和
LNK1120 1 unresolved externals
我研究发现,一次使用#pragma应该可以解决问题,但事实并非如此。我也尝试过重新制作该项目,但这似乎是它自己的错误。
ConsoleApplicationASS.cpp
#include<iostream>
#include<string>
#include <fstream>
#include <vector>
#include "pch.h"
#include "word.h"
#include "dictionary.h"
using namespace std;
int main()
{
Dictionary dic;
dic.loadDictionary();
}
dictionary.cpp
#include "dictionary.h"
#include "word.h"
#include <string>
#include <vector>
using namespace std;
void Dictionary::loadDictionary()
{
string filename = "dictionary.txt";
string word = "", def = "", type = "", whitespace = "";
cout << "Attempting to read text file...\n";
ifstream dicFile(filename);
vector<Word> wordObjects;
if (dicFile.is_open())
{
while (!dicFile.eof())
{
getline(dicFile, word);
getLine(dicFile, def);
getLine(dicFIle, type);
getLine(dicFile, whitespace);
Word word1(word, def, type);
wordObjects.push_back(word1);
}
dicFile.close();
}
else cout << "Unable to open file";
system("pause");
}
dictionary.h
#pragma once
#include <vector>
#include "word.h"
class Dictionary
{
public:
void loadDictionary();
vector<Word> wordObjects;
private:
};
我希望我没有包含太多的代码,但是我似乎确实对这个错误感到困惑。
感谢高级帮助!