【发布时间】:2016-03-25 03:46:30
【问题描述】:
我在标题中遇到了错误,导致很多其他错误,我真的不知道如何解决它,当我尝试在 main 中声明 ListeTriee 列表时,错误就开始了,在此之前我没有有任何问题。
错误:
In file included from Cours.h:10:0,
from ListeBase.h:13,
from ListeBase.cxx:1:
Liste.h:12:51: error: expected template-name before ‘<’ token
template<typename T> class Liste: public ListeBase<T>
^
Liste.h:12:51: error: expected ‘{’ before ‘<’ token
Liste.h:12:51: error: expected unqualified-id before ‘<’ token
In file included from ListeBase.h:13:0,
from ListeBase.cxx:1:
Cours.h:19:20: error: field ‘groupes’ has incomplete type
Liste<int> groupes;
^
Cours.h: In member function ‘void Cours::insererGroupe(int)’:
Cours.h:28:13: error: ‘groupes’ was not declared in this scope
groupes.insere(val);
文件是:
ListeBase.h:
#ifndef LISTE_BASE
#define LISTE_BASE
#include <stdlib.h>
#include <iostream>
#include <time.h>
using namespace std;
#include "Timing.h"
#include "Professeur.h"
#include "Groupe.h"
#include "Local.h"
#include "Cours.h"
template<typename T> struct Cellule
{
T valeur ;
Cellule<T> *suivant ;
Cellule(T v, Cellule<T> *s) : valeur(v), suivant(s) {};
};
template<typename T> class Iterateur;
template<typename T> class ListeBase
{
protected:
Cellule<T> *pTete ;
public:
ListeBase();
~ListeBase();
bool estVide() const;
int getNombreElements() const;
void Affiche() const;
virtual T* insere(const T & val)=0;
friend class Iterateur<T>;
};
#endif
Liste.h
#ifndef LISTE
#define LISTE
#include <stdlib.h>
#include <iostream>
#include <time.h>
using namespace std;
#include "ListeBase.h"
#include "Timing.h"
template<typename T> class Liste: public ListeBase<T>
{
public:
T* insere(const T & val);
};
#endif
课程.h
#ifndef COURS
#define COURS
#include <stdlib.h>
#include <string.h>
#include <iostream>
using namespace std;
#include "Liste.h"
#include "Event.h"
#include "Professeur.h"
#include "Groupe.h"
class Cours: public Event
{
private:
char* professeur;
Liste<int> groupes;
public:
Cours();
Cours(const Cours &);
~Cours();
const char* getProfesseur() const;
void setProfesseur(Professeur &);
void insererGroupe(int val)
{
groupes.insere(val);
}
void Affiche();
};
#endif
谢谢,如果您需要更多详细信息,请询问。
【问题讨论】:
-
@JoachimPileborg 这是正确答案。你能打出来吗?