erreur: template argument required for ‘struct Liste’
Bonjour,
J'ai créé une liste chainé en c++. Pour cela j'ai deux classes : liste et maillon.
Elle marchait, mais j'ai voulu rajouter les templates et la sa marche plus. J'ai du mal transformer ma classe en template. Voici l'erreur à la compilation :
Citation:
g++ -I/usr/openwin/include -c -Wno-deprecated Client.cc
Maillon.cc: In instantiation of ‘Maillon<float>’:
Liste.cc:18: instantiated from ‘Liste<T>& Liste<T>::operator+(T) [with T = float]’
Client.cc:9: instantiated from here
Maillon.cc:11: erreur: template argument required for ‘struct Liste’
Maillon.cc: In member function ‘void Liste<T>::affiche() const [with T = float]’:
Client.cc:10: instantiated from here
Maillon.cc:11: erreur: ‘Maillon<float>* Maillon<float>::suiv’ is private
Liste.cc:35: erreur: à l'intérieur du contexte
Maillon.cc:10: erreur: ‘float Maillon<float>::data’ is private
Liste.cc:36: erreur: à l'intérieur du contexte
Maillon.cc: In member function ‘Liste<T>& Liste<T>::operator+(Maillon<T>&) [with T = float]’:
Liste.cc:19: instantiated from ‘Liste<T>& Liste<T>::operator+(T) [with T = float]’
Client.cc:9: instantiated from here
Maillon.cc:11: erreur: ‘Maillon<float>* Maillon<float>::suiv’ is private
Liste.cc:26: erreur: à l'intérieur du contexte
make: *** [Client.o] Erreur 1
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 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
|
template<class T>
class Maillon
{
private:
T data;
Maillon<T> *suiv;
public:
Maillon() : data(0), suiv(NULL){};
Maillon(const Maillon<T>& e) : data(e.data), suiv(e.suiv){};
~Maillon(){};
Maillon<T>& operator=(const Maillon<T>& e) {
data = e.data;
suiv = e.suiv;
return *this;
}
Maillon(double d) : data(d), suiv(NULL){};
friend class Liste;
};
template<class T>
class Liste
{
private:
Maillon<T> *tete, *fin;
public:
Liste() : tete(NULL), fin(NULL) {};
// Ajout de maillons
Liste<T>& operator+(T data) {
Maillon<T> *maillon = new Maillon<T>(data);
return *this + (*maillon);
}
Liste<T>& operator+(Maillon<T> &m) {
if (tete == NULL) {
tete = &m;
} else {
fin->suiv = &m;
}
fin = &m;
return *this;
}
// Entrees-sorties
void affiche() const {
for (Maillon<T> *ptr = tete; ptr != NULL; ptr = ptr->suiv) {
std::cout << ptr->data << " ";
}
std::cout << std::endl;
}
}; |
Je suis depuis un moment sur l'erreur, mais je n'arrive pas à savoir pourquoi. Si vous pouviez m'aider ?