I am attempting to implement some small generic data structures as review and to learn more c++, but am running into problems with getting my basic template class to compile.
Header file:
template <class T>
class ArrayList {
public:
ArrayList(T dataToAdd[]);
};
C++ file:
#include <iostream>
#include "arrayList.hpp"
template <class T>
ArrayList<T>::ArrayList(T dataToAdd[]) {
std::cout << "ArrayList constructor" << std::endl;
}
main.cpp:
#include <iostream>
#include "arrayList.hpp"
int main(int argc, const char* argv[]) {
int data[3] = {1, 2, 3};
ArrayList<int> testList(data);
return 0;
}
I am thinking that the problem has to do with the array being passed into the constructor in main.cpp, as when I removed all parameters (from header, implementation, and actually calling the constructor) the program compiled fine.
The error I am receiving:
/usr/bin/ld: /tmp/cc5ra82s.o: in function `main':
main.cpp:(.text+0x46): undefined reference to `ArrayList<int>::ArrayList(int*)'
collect2: error: ld returned 1 exit status