Edit: This was not an issue with the template not being defined in the header. This error was caused by not defining a copy constructor.
I tried googling this but I couldn't find anything except for issues with people calling functions without the proper parameters and things along those lines. So, here's a very small chunk from main. I have created a templated container class and initialized test as one to hold strings. sorted.h is included in both .cpp files.
Error here: https://i.stack.imgur.com/uGeeZ.jpg
// Test assignment operator
// Can test copy constructor by changing following two lines to
// sorted<string> test(songs);
sorted<string> test;
test = songs; // Error occurs when commenting this line back in.
Here is my overloaded assignment operator. I assume this is what's causing the problem since commenting the line that would use it is what causes the linker error. Anyone have an idea what I'm doing wrong here?
//Overloaded assignment operator. (sorted.cpp)
template <class T>
sorted<T> sorted<T>::operator=(const sorted<T>& srtd){
if (this != &srtd){
delete [] m_data;
delete [] m_randfinal;
m_data = new T[srtd.m_capacity];
m_randfinal = new T[srtd.m_size];
m_size = srtd.m_size;
m_capacity = srtd.m_capacity;
for (int i = 0; i < m_size; i++){
m_data[i] = srtd.m_data[i];
m_randfinal[i] = srtd.m_randfinal[i];
}
}
return *this;
}
Declaration in sorted.h.
// Overloaded assignment operator
sorted<T> operator=(const sorted<T>& srtd);