Problème avec les templates.
Bonjour, j'ai un problème avec la réalisation d'une liste chainée générique.
C'est la classe Iterator qui pose problème. Mon compilateur est GCC.
La classe cellule.
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
#ifndef CELLULE_H
#define CELLULE_H
#include "iterator.h"
template<typename T>class Cellule
{
friend class Iterator<T>;
public:
Cellule(T & i) : valeur(&i) , suivante(NULL) {};
Cellule() : valeur(NULL) , suivante(NULL) {};
template<typename U> friend class Iterator;
private:
T * valeur ;
Cellule * suivante ;
};
#endif // CELLULE_H |
Voici la classe Iterator
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
#ifndef ITERATOR_H
#define ITERATOR_H
#include "cellule.h"
template<typename T>class Iterator
{
public:
Iterator();
Iterator( Cellule<T> & cell ) ; courante(cell) , firstCell(cell);//ligne 10
void allerDebut();
void allerFin();
bool avancer();
void ajouter(T & elem);
void supprimer();
private:
Cellule<T> & courante ;
Cellule<T> & firstCell ;
};
//#include "iterator.tpp"
#endif |
A la compilation, j'obtiens les erreurs suivantes (entre autre).
Code:
1 2 3 4 5 6
|
C:/Program Files (x86)/CodeLite/TP_CPP/Projet_CPP/liste/iterator.h:10: error: expected ')' before '<' token
C:/Program Files (x86)/CodeLite/TP_CPP/Projet_CPP/liste/iterator.h:10: error: 'cell' has not been declared
C:/Program Files (x86)/CodeLite/TP_CPP/Projet_CPP/liste/iterator.h:10: error: ISO C++ forbids declaration of 'courante' with no type
C:/Program Files (x86)/CodeLite/TP_CPP/Projet_CPP/liste/iterator.h:10: error: 'cell' has not been declared
C:/Program Files (x86)/CodeLite/TP_CPP/Projet_CPP/liste/iterator.h:10: error: ISO C++ forbids declaration of 'firstCell' with no type |
Voilà je comprend pas pourquoi il manque une parenthèse.
J'aimerais également savoir comment utiliser la liste d'initialisation pour initialiser les deux variables membres de "Iterator" avec le constructeur par défaut de Cellule, à la ligne 9.
Merci d'avance !