Ошибка компилятора при объявлении класса-друга шаблона в пределах класса-шаблона
Я пытался реализовать свой собственный класс связанного списка для дидактических целей.
Я указал "Список" класс как друг внутри объявления Iterator, но это некажется, компилируется.
Это интерфейсы 3 классов I 'мы использовали:
node.h:
#define null (Node *) 0
template
class Node {
public:
T content;
Node* next;
Node* prev;
Node (const T& _content) :
content(_content),
next(null),
prev(null)
{}
};
Iterator.h:
#include "Node.h"
template
class Iterator {
private:
Node* current;
Iterator (Node *);
public:
bool isDone () const;
bool hasNext () const;
bool hasPrevious () const;
void stepForward ();
void stepBackwards ();
T& currentElement () const;
friend class List;
};
list.h
#include
#include "Iterator.h"
template
class List {
private:
Node* head;
Node* tail;
unsigned int items;
public:
List ();
List (const List&);
List& operator = (const List&);
~List ();
bool isEmpty () const {
return items == 0;
}
unsigned int length () const {
return items;
}
void clear ();
void add (const T&);
T remove (const T&) throw (std::length_error&, std::invalid_argument&);
Iterator createStartIterator () const throw (std::length_error&);
Iterator createEndIterator () const throw (std::length_error&);
};
И это тестовая программа, которую япытался бежать:
trial.cpp
using namespace std;
#include
#include "List/List.cc"
int main ()
{
List myList;
for (int i = 1; i