错误:在C ++中'<'标记之前的预期模板名称

时间:2015-12-18 12:16:32

标签: c++ list templates

我在标题中得到了错误导致了很多其他错误,我真的不知道如何解决它,当我尝试在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

Cours.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

谢谢,如果您需要更多详细信息,请询问。

1 个答案:

答案 0 :(得分:3)

您有循环依赖:Cours.h取决于Liste.hListeBase.h取决于依赖于Cours.h依赖的Liste.hCours.h ...

我认为ListeBase.h中没有public void showForgetPassword() { final Dialog dialog=new Dialog(context); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setCanceledOnTouchOutside(false); dialog.setContentView(R.layout.dialog_forget_password); final EditText edt_ForgotPassword=(EditText)dialog.findViewById(R.id.edt_ForgotPassword); dialog.findViewById(R.id.btn_OK).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { String email = edt_ForgotPassword.getText().toString().trim(); if(email.equalsIgnoreCase("")){ edt_ForgotPassword.setError(context.getResources().getString(R.string.emailError)); }else if (!isValidEmail(email)) { edt_ForgotPassword.setError(context.getResources().getString(R.string.invalidEmail)); }else{ List<NameValuePair> params = new ArrayList<NameValuePair>(); params.add(new BasicNameValuePair("email", email)); String serverURL = ServerUrl.serverForgotPassword; if(!cd.isConnectingToInternet()){ dialogs.showNetworkDialog(context.getResources().getString(R.string.internet)); }else{ if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB){ getJSON = new GetJSON(context,params,serverURL); getJSON.registerListener(CommonDialog.this); getJSON.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); }else{ getJSON = new GetJSON(context,params,serverURL); getJSON.registerListener(CommonDialog.this); getJSON.execute(); } } dialog.dismiss(); } } }); dialog.findViewById(R.id.btn_Cancel).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { dialog.dismiss(); } }); //::::::::::::::font function:::::::::::::::::::::::::::::::::::::::::::::::::::: ViewGroup root = (ViewGroup)dialog.findViewById(R.id.rl_DialogCommon); fontType=new FontType(context,root); dialog.show(); } 包含的任何原因,因此请不要将其包含在import Data.List import System.IO primeNumbers = [3,5,7,11] morePrime = primeNumbers ++ [13,17,19] 中。你不应该包含你实际上不需要的头文件,如果可以避免,你不应该在头文件中包含头文件,而是按照所需的顺序在源文件中包含所有需要的头文件。