Strukturen verknüpfen



  • Hallo,

    wie kann ich erreichen, dass in folgendem Beispiel ich die beiden Strukturen der selben Klasse per Zeiger verknüpfen kann?

    header

    #include <iostream.h>
    #include <conio.h>
    
    class Kset
    {
    private:
            struct Knoten
            {
             int Inhalt;
             int Priority;
             Knoten *pNext;
             Knoten *pFront;
            };
    
            Knoten *Kopf;
            Knoten *Sentinel;
    
            int Anzahl;
    
            struct Un
            {
             Un *pNext;
             Un *pFront;
            };
    
    public:
            Kset();
            Kset(const Kset & obj);
            Kset(const int *obj, const int Array);
            ~Kset();
    
            void insert_front(int obj);
            void insert_back(int obj);
            void insert_pos(int obj, int pri);
            void delete_front();
            void delete_back();
            void display();
            void push_array(const int *obj, const int Array);
    
            friend ostream & operator << (ostream &os, Kset & kl);
            friend istream & operator >> (istream& is, Kset & kl);
    
            Kset& operator = (const Kset &alt);
    };
    
    #include "impl.hpp"
    

    Und zwar möchte ich, dass die Struktur "Knoten" per Frontzeiger auf die Struktur
    "Un" zeigt

    Also etwa so:

    Knoten *pNew = new Knoten;
    Un *pFrei = new Un;
    pNew->pFront = pFrei
    

    Wenn ich es versuche kommt folgende Fehlermeldung: [C++ Fehler] impl.hpp(78): E2034 Konvertierung von 'Kset::Un *' nach 'Kset::Knoten *' nicht möglich



  • Mr. Blonde schrieb:

    Knoten *pNew = new Knoten;
    Un *pFrei = new Un;
    pNew->pFront = pFrei
    

    Wenn ich es versuche kommt folgende Fehlermeldung: [C++ Fehler] impl.hpp(78): E2034 Konvertierung von 'Kset::Un *' nach 'Kset::Knoten *' nicht möglich

    Die Fehlermeldung sagts ja schon... pFron ist doch vom Typ Knoten* und pfrei von Typ Un*.

    Wenn schon so

    struct Knoten
            {
             int Inhalt;
             int Priority;
             Un *pNext;
             Un *pFront;
            };
    

    Aber da Un da noch nicht bekannt ist musst du eine Vorwärtsdeklaration einfügen...



  • danke ... aber irgendwie will er nicht so richtig ... es kommt der gleiche fehler

    #include <iostream.h>
    #include <conio.h>
    
    struct Un;
    
    class Kset
    {
    private:
            struct Knoten
            {
             int Inhalt;
             int Priority;
             Knoten *pNext;
             Knoten *pFront;
             Un *pNext2;
             Un *pFront2;
            };
    
            Knoten *Kopf;
            Knoten *Sentinel;
    
            int Anzahl;
    
            struct Un
            {
             Un *pNext2;
             Un *pFront2;
            };
    
    public:
            Kset();
            Kset(const Kset & obj);
            Kset(const int *obj, const int Array);
            ~Kset();
    
            void insert_front(int obj);
            void insert_back(int obj);
            void insert_pos(int obj, int pri);
            void delete_front();
            void delete_back();
            void display();
            void push_array(const int *obj, const int Array);
    
            friend ostream & operator << (ostream &os, Kset & kl);
            friend istream & operator >> (istream& is, Kset & kl);
    
            Kset& operator = (const Kset &alt);
    };
    
    #include "impl.hpp"
    
    Knoten *pNew = new Knoten;
    Un *pLeer1 = new Un;
    
    pNew->pFront2 = pLeer1;
    

Anmelden zum Antworten