0

I made this code:

Item.h:

#include <iostream>
using namespace std;

template <class T>
class Item
{
private:
    Item<T> * next;
    Item<T> * prev;
    T * data;

public:
    Item(T * pData = NULL);
    ~Item();
};

I also made Item.cpp:

#include "Item.h"

template<class T>
Item<T>::Item(T * pData) : data(pData), next(NULL), prev(NULL) {}

template<class T>
Item<T>::~Item() {}

And this is the Main:

#include "Item.h"

int main()
{
    int * s1 = new int(5);
    Item<int> * i = new Item<int>(s1);

    system("pause");
    return 0;
}

When I am trying to separate the Item.h to Item.cpp (if I don't write declaration), I get this error:

Error LNK2019 unresolved external symbol "public: __thiscall Item<int>::Item<int>(int *)" (??0?$Item@H@@QAE@PAH@Z) referenced in function _main.

melpomene
  • 84,125
  • 8
  • 85
  • 148
Opal Koren
  • 51
  • 1
  • 7

0 Answers0