I get an error at the build stage "undefined reference to LIST<int>::~List"
I'm trying to learn about templates and my book asked me to make the class into a template then declare the object.
Please show me what I am doing wrong and help me fix the error.Thanks.
#include <iostream>
template <class T>
class List
{
private:
public:
List():head(0),tail(0),theCount(0) {}
virtual ~List();
void Insert( int value );
void append( int value );
int is_present( int value ) const;
int is_empty() const { return head == 0; }
int count() const { return theCount; }
private:
class ListCell
{
public:
ListCell(int value, ListCell *cell = 0):val(value),next(cell){}
int val;
ListCell *next;
};
ListCell *head;
ListCell *tail;
int theCount;
};
int main()
{
List <int> myList;
}
#include <iostream>
template <class T>
class List
{
private:
public:
List():head(0),tail(0),theCount(0) {std::cout <<"List constructor called.\n";}
virtual~List(){std::cout<<"List destructor called.\n";}
void Insert( int value );
void append( int value );
int is_present( int value ) const;
int is_empty() const { return head == 0; }
int count() const { return theCount; }
private:
class ListCell
{
public:
ListCell(int value, ListCell *cell = 0):val(value),next(cell){}
int val;
ListCell *next;
};
ListCell *head;
ListCell *tail;
int theCount;
};
int main()
{
List <int> myList;
}