Probleme mit std::list



  • Hi,
    ich suche schon seit einer weile einen Fehler in dem Quelltext finde aber keinen. bcb meldet da:

    [C++ Fehler] list.h(110): E2450 Undefinierte Struktur 'IEntry'
    [C++ Fehler] XMLParser.h(58): E2450 Undefinierte Struktur 'EntryList'
    [C++ Fehler] XMLParser.h(58): E2449 Größe von 'subItems_' unbekannt oder Null
    [C++ Fehler] XMLParser.h(58): E2450 Undefinierte Struktur 'EntryList'
    

    Im Quelltext finde ich aber nichts was falsch sein kann.

    typedef std::list<class IEntry> EntryList; 
    
    [...]
    
    class IEntry
    {
       friend class Document;
    protected:
       EntryList subItems_;
       AttributeList attributes_;
    
       std::string toString() const;
    public:
       const EntryList & getSubItems() const;
       const AttributeList & getAttributes() const;
       const std::string & getText() const;
    };
    [...]
    


  • Der Compiler kennt zum Zeitpunkt des typedefs Deine Klasse nicht.

    Les mal ein wenig zum Thema forwarddeklaration.

    Du wirst im C++ Forum einige Threads finden die Dir weiterhelfen.

    (Ich würde das Typedef in die Klasse aufnehmen, bin mir aber nicht sicher ob das jetzt helfen würde O🤡 )



  • Knuddlbaer schrieb:

    Der Compiler kennt zum Zeitpunkt des typedefs Deine Klasse nicht.

    Das kann nicht sein, denn

    typedef std::list<class Attribute> AttributeList;
    

    lässt sich kompilieren. Obwohl, außer den Namen und der Schnittstellen der Klassen, sind sie beide gleich.



  • Knuddlbaer schrieb:

    (Ich würde das Typedef in die Klasse aufnehmen, bin mir aber nicht sicher ob das jetzt helfen würde O🤡 )

    Hat nicht geholfen. 😞



  • typedef std::list<class IEntry> EntryList;  //<<-- Wo bitte schön weiss der Compiler von der Klasse die erst 
    
    [...] 
    
    class IEntry                                     // <<-- HIER steht ?
    { 
       friend class Document; 
    protected: 
       EntryList subItems_; 
       AttributeList attributes_; 
    
       std::string toString() const; 
    public: 
       const EntryList & getSubItems() const; 
       const AttributeList & getAttributes() const; 
       const std::string & getText() const; 
    }; 
    [...]
    

    Wenn Du Dir sicher bist das es dennoch richtig ist stell Deine Frage anderst.



  • Auch forwarddeklaration (wenn das eine ist):

    class IEntry;
    
    typedef std::list<IEntry> EntryList;
    

    bringt mich nicht weiter.



  • Knuddlbaer schrieb:

    typedef std::list<class IEntry> EntryList;  //<<-- Wo bitte schön weiss der Compiler von der Klasse die erst
    

    Der gesamte Quelltext. Wenn ich alles wo EntryList vorkommt ausklamere dann kommt kein Fehler (obwohl - Deiner Vermutung nach - der bei typedef std::list<class Attribute> AttributeList; auftreten sollte.

    //---------------------------------------------------------------------------
    
    #ifndef XMLParserH
    #define XMLParserH
    
    #include <string>
    #include <list>
    //---------------------------------------------------------------------------
    namespace XML
    {
    
    typedef std::list<class IEntry> EntryList;
    typedef std::list<class Attribute> AttributeList;
    //---------------------------------------------------------------------------
    class Error
    {};
    //---------------------------------------------------------------------------
    class EParseError : public Error
    {
    private:
       std::string filePath_;
       size_t line_;
    public:
       EParseError(const std::string & filePath, size_t line);
       const std::string & getFilePath() const;
       size_t getLine() const;
    };
    //---------------------------------------------------------------------------
    class EInvalidKeyword : public EParseError
    {
    public:
       EInvalidKeyword(const std::string & filePath, size_t line);
    };
    //---------------------------------------------------------------------------
    class Attribute
    {
       friend class Document;
    private:
       std::string key_;
       std::string value_;
    
       Attribute(const std::string & str);
    public:
       const std::string & getKey() const;
       void setKey(const std::string & key);
    
       const std::string & getValue() const;
       void setValue(const std::string & value);
    
       std::string toString() const;
    };
    //---------------------------------------------------------------------------
    class IEntry
    {
       friend class Document;
    protected:
       EntryList subItems_;
       AttributeList attributes_;
    
       std::string toString() const;
    public:
       const EntryList & getSubItems() const;
       const AttributeList & getAttributes() const;
       const std::string & getText() const;
    };
    //---------------------------------------------------------------------------
    class Document : public IEntry
    {
    private:
       void parse();
    public:
       void loadFromFile(const std::string & filePath);
       void saveToFile(const std::string & filePath);
    };
    //---------------------------------------------------------------------------
    } // namespace XML
    #endif
    


  • Knuddlbaer schrieb:

    Der Compiler kennt zum Zeitpunkt des typedefs Deine Klasse nicht.
    Les mal ein wenig zum Thema forwarddeklaration.
    Du wirst im C++ Forum einige Threads finden die Dir weiterhelfen.

    Noch nen Tipp:

    Benutze mal die Suchfuntion. Findest Du oben rechts.

    Hier ein wenig technische Details:

    http://c-plusplus.net/forum/viewtopic.php?t=4751&highlight=querverweis



  • Ich seh gerade das Du

    typedef std::list<class IEntry> EntryList; 
    	typedef std::list<class Attribute> AttributeList;
    

    schreibst.

    Da ich nicht mal weiß ob list<class T> myList; legaler C++ Code ist kann ich Dir nicht weiterhelfen.
    Ich persönlich bin der Meinung das es nicht legal ist und es

    typedef std::list<IEntry> EntryList; 
    	typedef std::list<Attribute> AttributeList;
    

    heissen müsste.

    Wenn es doch legal ist hätte ich gerne ne kurze Erklärung zu 🤡

    sry, muss passen



  • Knuddlbaer schrieb:

    Noch nen Tipp:

    Benutze mal die Suchfuntion. Findest Du oben rechts.

    Hier ein wenig technische Details:

    http://c-plusplus.net/forum/viewtopic.php?t=4751&highlight=querverweis

    Danke dass Du für mich gesucht, hast. Den Thread habe ich zwar nicht so ganz verstanden, aber in irgendeinem anderen habe ich gelesen, dass es
    so heißen müsste

    class IEntry
                    //       | Ein Zeiger, weil der benötigte Speicher 
                    //         vorher nicht bekannt ist.
    typedef std::list<class IEntry *> EntryList;
    

    Aber die Frage bleibt offen wieso lässt sich die andere typdefinition ohne Probleme kompilieren.

    Wenn es doch legal ist hätte ich gerne ne kurze Erklärung hinzu 🤡

    Ich kann keine liefern. Lässt sich auf jeden Fall kompilieren => ist legal (zumindest für BCB).

    EDIT: Mit dem Zeiger lässt es sich kompileren.

    Danke für die schnelle Hilfe.



  • int * foo()
    {
      int a;
      return &a;
    }
    

    Wird auch Compiliert.

    Ich kann mir nur vorstellen das class T als FWD Deklaration gelten könnte. Ka, da wart ich mal bis Hume oder Shadow was zu schreiben.

    Ansonsten haste das gesuchte gefunden :xmas2:


Anmelden zum Antworten