I wanted to create a generic array that could contain any type of data.
The class looks like this GenericArray.h
:
#pragma once
#include "LinkedList.h"
template<class T>
class GenericArray
{
public:
GenericArray();
void push(T to_push);
private:
LinkedList<T>* _first;
};
And the implementation looks like this GenericArray.cpp
:
#include "GenericArray.h"
template<class T>
GenericArray<T>::GenericArray() { this->_first = NULL; }
template<class T>
void GenericArray<T>::push(T to_push)
{
LinkedList<T>* new_node = new LinkedList<T>(to_push);
new_node->_next = NULL;
if (this->_first == NULL)
{
this->_first = new_node;
return ;
}
else
{
LinkedList<T>* last_nude = this->_first;
while (current->_next != NULL)
{
current = current->_next;
}
last_nude->_next = new_node;
}
}
But yet, when Im trying to build a file, I get this ERROR:
Severity Code Description Project File Line Suppression State Error LNK2019 unresolved external symbol "public: __thiscall GenericArray::GenericArray(void)" (??0?$GenericArray@H@@QAE@XZ) referenced in function _main Homework5 c:\Users\SSS\documents\visual studio 2017\Projects\Homework5\Homework5\main.obj 1
And:
Severity Code Description Project File Line Suppression State Error LNK2019 unresolved external symbol "public: void __thiscall GenericArray::push(int)" (?push@?$GenericArray@H@@QAEXH@Z) referenced in function _main Homework5 c:\Users\VVV\documents\visual studio 2017\Projects\Homework5\Homework5\main.obj 1
Obviously I did somthing wrong when using bad with templates. But I followed my code in order to find the problen, and I couldnt find anything suspicious.
If you can enlighten me, I will me gratful. Thanks.