M
MiniDisc_2k2
I have a class:
template <class T>
class linkedlist
{
protected:
class node
{
public:
T data;
node* next;
node* prev;
node() {next = NULL; prev = NULL;};
~node();
} *first;
public:
~linkedlist() { if (first!=NULL) delete first;};
void AddElement(const T &data);
T AddElement(istream &input);
void Append(const linkedlist* const data);
linkedlist() {first = NULL;};
};
template <class T>
linkedlist<T>::node::~node()
{
if (next!=NULL)
delete next;
if (prev!=NULL)
prev->next = NULL;
}
That code is in linkedlist.h (some code was taken out). Please note that I
have defined NULL (if undefined) to be 0.
In main.cpp:
#include <iostream>
#include "linkedlist.h"
using namespace std;
int main(int argc, char* argv[])
{
...some code...
linkedlist<int> intlist;
.... some more code...
return 0;
}
When I compile this code, I get a linker error:
Linking...
main.obj : error LNK2001: unresolved external symbol "public: __thiscall
linkedlist<int>::node::~node(void)" (??1node@?$linkedlist@H@@QAE@XZ)
Debug/main.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
Of course, I know what this means. It's saying that I never defined the
destructor to node. I thought I did. What am I doing wrong?
template <class T>
class linkedlist
{
protected:
class node
{
public:
T data;
node* next;
node* prev;
node() {next = NULL; prev = NULL;};
~node();
} *first;
public:
~linkedlist() { if (first!=NULL) delete first;};
void AddElement(const T &data);
T AddElement(istream &input);
void Append(const linkedlist* const data);
linkedlist() {first = NULL;};
};
template <class T>
linkedlist<T>::node::~node()
{
if (next!=NULL)
delete next;
if (prev!=NULL)
prev->next = NULL;
}
That code is in linkedlist.h (some code was taken out). Please note that I
have defined NULL (if undefined) to be 0.
In main.cpp:
#include <iostream>
#include "linkedlist.h"
using namespace std;
int main(int argc, char* argv[])
{
...some code...
linkedlist<int> intlist;
.... some more code...
return 0;
}
When I compile this code, I get a linker error:
Linking...
main.obj : error LNK2001: unresolved external symbol "public: __thiscall
linkedlist<int>::node::~node(void)" (??1node@?$linkedlist@H@@QAE@XZ)
Debug/main.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
Of course, I know what this means. It's saying that I never defined the
destructor to node. I thought I did. What am I doing wrong?