I'm trying to learn different technics for C++ and one of them is using Templates with dynamic memory.
Only problem is that i keep getting a "undefined reference to" error;
My code is pretty simple. I've got a class named Array using a templat that holds a un initialized array and a size variable, it also has a constructor, a copy constructor, destructor and overrides the [] operator.
No need to post the implementation of the functions.
template <class T>class Array {public: int size;private: T *arrayPtr[];public: Array(int); Array(const Array &); virtual ~Array(); T &operator[](int);};
The main function is straight forward. I create a pointer and try to allocate memory to it.
#include <iostream>#include "Array.h"#include "Object.h"using namespace std;int main(){//creating a pointer and allocating memory for a new array of size 5 and type Object Array<Object> *array1 = new Array<Object>(5);//creating a pointer and allocating memory for a copy of array1. Array<Object> *array2 = new Array<Object>(array1);//Some other code that's not important. delete array1; delete array2; return 0;}
Problem here is that on both pointers i get the following message "...../src/Main.cpp:18: undefined reference to `Array<Object>::Array(int)'"
Any suggestions?