尝试从我的主方法调用类方法时遇到链接器错误。我已经寻找答案,但似乎没有任何适用于我的问题,任何帮助将不胜感激。
文件系统.h
#ifndef FILE_SYSTEM_H
#define FILE_SYSTEM_H
#include <fstream>
#include <string>
#include <random>
#include "SortingAlgorithms.h"
#include "SortingAlgorithms.cpp"
using namespace std;
class FileSystem
{
private:
ifstream inFile;
ofstream outFile;
template <class T>
void fillArrays( T randomArray[], T sortedArray[], T backwardArray[], int size );
public:
FileSystem();
~FileSystem();
bool openFile(string fileName);
void writeToFile(string output);
void createTestFiles(string testFiles[]);
template <class T>
void fillArrayFromFile(T list[], int size);
};
#endif
fillArrayFromFile
template <class T>
void FileSystem::fillArrayFromFile(T list[], int size)
{
int i;
for(i = 0; i < size; i ++)
{
inFile >> list[i];
}
inFile.clear();
inFile.seekg(inFile.beg);
}
pa2.cpp
#include <iostream>
#include <ctime>
#include <string>
#include <iomanip>
#include "TimerSystem.h"
#include "FileSystem.h"
using namespace std;
int main()
{
FileSystem file;
int testArray[10];
file.openFile("test-10-0.txt");
file.fillArrayFromFile(testArray, 10);
}
错误:
pa2.obj : error LNK2019: unresolved external symbol "public: void __thiscall FileSystem::fillArrayFromFile<int>(int * const,int)" (??$fillArrayFromFile@H@FileSystem@@QAEXQAHH@Z) referenced in function _main
C:\Users\Matt\Google Drive\Programming\Data Structures & Algorithms\PA2-9-15-2012\Debug\PA2.exe : fatal error LNK1120: 1 unresolved externals
再次感谢。