Hi.
What is the right syntax for implementing the .cpp of a template class?
Consider this LinkedList.h file:
Code:
#include<iostream>
#include"Iterator.h"
template <class T>
class LinkedList {
public:
LinkedList();
virtual ~LinkedList();
// more List-related methods here...
private:
template <class T>
class Node {
public:
Node(T d, Node<T>* n=NULL, Node<T>* p=NULL):
data(d),
next(n),
prev(p){}
Node<T>* next;
Node<T>* prev;
T data;
};
template <class T>
class ListIterator: public Iterator<T> {
public:
virtual T& operator*();
virtual T* operator->();
virtual void operator++();
virtual void operator--();
private:
Node<T>* current;
};
};
How should the implementation for the LinkedList constructor, for example, should look like in the LinkedList.cpp file?
I tried this:
Code:
#include "LinkedList.h"
template <class T>
LinkedList<T>::LinkedList<T>() {
// constructor
}
LinkedList<T>::~LinkedList<T>() {
// destructor
}
But the compiler wouldn't accept it.