Hello!
I have built a LinkedList template class and am trying to test out its functions on a user defined type (another class called Animal in the example below).
When I instantiate a Linked List object with an int type, there are no issues. However, when I try to instantiate a Linked List object with my user defined "Animal" type, I receive the following error message:
[1/2] Building CXX object CMakeFiles/LinkedListcpp.dir/main.cpp.obj
[2/2] Linking CXX executable LinkedListcpp.exe
FAILED: LinkedListcpp.exe
C:\bin\mingw\bin/ld.exe: CMakeFiles/L/CLionProjects/LinkedListcpp/main.cpp:26: undefined reference to `LinkedList<Animal>::LinkedList(int)'
collect2.exe: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.
Note the name of the project is LinkedListcpp.
Here is the LinkedList code in linked_list.cpp:
1 2 3 4 5 6
|
template<typename T> LinkedList<T>::LinkedList(int item) {
this->first = nullptr;
this->last = nullptr;
this->size = 0;
this->itemSize = item;
}
| |
Here is the declaration in linked_list.h:
LinkedList(int);
Here is what I am trying to do in main.cpp:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
#include <iostream>
#include "linked_list.h"
class Animal{
public:
Animal(std::string str){
this->name = str;
}
std::string getName(){
return this->name;
}
private:
std::string name;
};
int main() {
LinkedList<Animal>* AList = new LinkedList<Animal>(0);
return 0;
}
| |
Any suggestions or insight would be greatly appreciated.