LNK2019 unresolved external symbol
I'm working on a program that reads in values from a file 3 at a time and stores them separately in a vector. I keep getting this error when I run the program, and I can't figure out why. The class that reads in the input file is a template so it can read in numbers of any type, so I might have some problem with all the template stuff, because I'm new to it and the book I'm learning from doesn't go in to much detail. Anyway, here are the files:
Code:
//class header file
#include <vector>
template <typename T>
class TextFile
{
public:
void readFile();
void printValues() const;
private:
std::vector< T > inputValues;
};
//class implementation file
#include <iostream>
#include "TextFile.h"
#include <fstream>
#include <vector>
#include <cstdlib>
#include <algorithm>
#include <iterator>
using namespace std;
template <typename T>
void TextFile<T>::readFile()
{
ifstream inFile("TopicIinBasic.txt");
if (!inFile)
{
cout << "File open failed. Program ending" << endl;
exit(1);
}
while (!(inFile.eof()))
{
T tempVal = 0;
string temp;
stringstream ss;
getline(inFile, temp); //Read in up to newline character
if (inFile.fail())
{
cout << "Input from file failed. Program ending." << endl;
inFile.close();
exit(1);
}
if (count(temp.begin(), temp.end(), '/') != 2)
{
cout << "Error in input. Program ending." << endl;
inFile.close();
exit(1);
}
replace(temp.begin(), temp.end(), '/', ' ');
ss << temp;
for (int i = 0; i < 3; i++)
{
ss >> tempVal;
inputValues.push_back(tempVal);
}
}
inFile.close();
}
template <typename T>
void TextFile<T>::printValues() const
{
ostream_iterator< T > output(cout, "\n");
copy(inputValues.begin(), inputValues.end(), output);
}
//main
#include <iostream>
#include "TextFile.h"
using namespace std;
int main()
{
TextFile<unsigned short int> text;
text.readFile();
cout << "Display input: " << endl;
text.printValues();
return 0;
}
//error message
1>TopicI.obj : error LNK2019: unresolved external symbol "public: void __thiscall TextFile<unsigned short>::printValues(void)const " (?printValues@?$TextFile@G@@QBEXXZ) referenced in function _main
1>TopicI.obj : error LNK2019: unresolved external symbol "public: void __thiscall TextFile<unsigned short>::readFile(void)" (?readFile@?$TextFile@G@@QAEXXZ) referenced in function _main
fatal error LNK1120: 2 unresolved externals
There it is; if anyone could point me in the direction of the problem that'd be awesome. Thanks.
Edit: Just noticed that I didn't have a _ in push_back, but putting that in did not fix the problem.
Edit2: Ok, so I just expanded the program quite a bit and added some more classes, and I'm having this same error between all of my classes and my main. In main, I make function calls to functions of classes 9 times, and I get 9 linker errors telling me basically the same thing as above. I still can't see what's wrong with it though. Any help would be appreciated greatly.
Edit 3: Wow, I'm an idiot. Totally forgot that the implementation for a class goes in the same file as the definition of it, unless they're linked differently than normal, which mine were not. Fixing that fixed all my linker problems, and then I just had to fix a couple small things and my program is now in business. Awesome.