错误:C++中"<"标记之前的预期模板名称
Error: Expected template-name before ‘<’ token in C++
我在标题中遇到了错误,导致很多其他错误,我真的不知道如何解决它,当我尝试声明一个列表 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
利斯特·
#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
库尔斯·
#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
谢谢,如果您需要更多详细信息,请询问。
你有一个循环依赖关系:Cours.h
取决于Liste.h
取决于ListeBase.h
取决于Cours.h
依赖。 Liste.h
......
我认为没有任何理由将Cours.h
包含在ListeBase.h
中,因此干脆不要将其包含在那里。您不应该包含您实际上不需要的头文件,恕我直言,如果可以避免,您根本不应该在头文件中包含头文件,而是按照所需的顺序将所有需要的头文件包含在源文件中。
相关文章:
- 请解释这句话(cout<<1+int((a<b)^((b-a)&1) )<<endl
- 呼叫运营商<<临时
- 如何防止clang格式在流运算符调用之间添加换行符<<
- <<操作员在下面的行中工作
- 如何显式调用运算符<<
- 模板操作员&lt;未打电话
- C / CUDA中的模板方法是3个角括号(&lt;&lt;&lt;)
- C - 创建矢量&lt; vector&lt; double&gt;&gt;矩阵具有分配而不是inizializ
- 错误:调用"std::vector<:vector<int>>::p ush_back(std::vector<std::__cxx11::basic_string<
- C 建造者Clang STD :: Sill,找不到超载的操作员&lt;
- 为什么STD :: MAP需要操作员&lt;以及我如何写一个
- 为什么“操作员”需要const但不是为“运营商&lt;”
- 为什么将此对向量&lt; map&lt; int,int&gt;&gt;中的地图进行更新.失败
- C :对矢量进行排序&lt; struct&gt;(结构有2个整数)基于结构的整数之一
- 明确的专业化“ CheckIntmap&lt;&gt;”实例化
- 什么是模板&lt;&gt;inline bla bla
- 左角支架解释为操作员&lt;而不是模板参数
- 编辑C Qlist&lt; object*&gt; gt;QML代码和一些QML警告中的模型
- 超载操作员&lt;&lt; - 必须是二进制操作员
- 没有匹配的“运营商&lt;&lt;”