Hi everyone,
For practice I am trying to code a simplified version of the template "std::list" but have come accross the LNK1120 + LNK2001 errors.
After looking in Visual Studio's documentation and some investigation, it seems the two most common causes are: 1) invalid calls in the code to things which don't exist, or 2) invalid project settings.
I can't seem to find any of these two problems in my code/project. On the other hand, I have also heard that these errors may be the result of some limitation in C++ where one template cannot call another one defined outside the calling header file, but I'm not sure about this last one.
In any case, I would really appreciate if someone could take a look at the following code and give me a hand. Thanks!
#ifndef LINKEDLIST_H
#define LINKEDLIST_H
#include <iostream>
#include <string>
#include "Linked Node 13_9_1.h"
using namespace std;
template <typename T>
class LinkedList
{
public:
LinkedList();
~LinkedList();
LinkedList(const LinkedList& rhs);
void append(T copieddata);
void printlist();
void destroy();
private:
LinkedNode* mFirst;
LinkedNode* mLast;
};
template <typename T>
LinkedList<T>::LinkedList()
{
mFirst = 0;
mLast= 0;
}
template <typename T>
LinkedList<T>::~LinkedList()
{
destroy();
}
template <typename T>
void LinkedList<T>::destroy()
{
if (mFirst != 0 )
{
LinkedNode<T>* current = mFirst;
while ( current != 0 )
{
LinkedNode<T>* oldnode = current;
current = current->next;
delete oldnode;
oldnode = 0;
}
}
}
template <typename T>
void LinkedList<T>::printlist()
{
LinkedNode<T>* current = mFirst;
while ( current != 0 )
{
cout << current->data << " ";
current = current->next;
}
}
template <typename T>
void LinkedList<T>::append(T copieddata)
{
LinkedNode<T>* newNode = new LinkedNode<T>;
newNode->data = copieddata;
if ( mFirst == 0 )
{
mFirst = newNode; mLast = newNode;
newNode->next = 0; newNode->prev = 0;
}
else
{
newNode->prev = mLast; mLast = newNode;
newNode->next = 0; newNode->prev->next = newNode;
}
}
template <typename T>
LinkedList<T>::(const LinkedList& rhs)
{
if ( rhs.mFirst != 0)
{
append(rhs.mFirst->data);
LinkedNode<T>* index = rhs.mFirst->next;
while ( index != 0)
{
append(index->data);
index = index->next;
}
}
}
#endif // LINKEDLIST_H