ADT List in einer ADT_List usw.



  • Hallöchen,

    ich möchte am Ende einen World_Enry in einer Adt_Liste (Einträge) in einer Adt_Liste (Z) in einer Adt_Liste(Y) in einer Adt_Liste (X) in einer Adt_Liste (Welt) stecken. Nun, dies funktioniert nicht 😕 😡 , da das Template wohl nicht funtioniert (s. Compiler-Fehler). Es folgt nun der Quellcode (gekürzt) - gäbe es eigentlich eine andere Methode der Implementation (z.B. mit universellen Templates)?

    /*
     * To change this license header, choose License Headers in Project Properties.
     * To change this template file, choose Tools | Templates
     * and open the template in the editor.
     */
    
    /* 
     * File:   main.cpp
     * Author: Simon
     *
     * Created on 13. September 2016, 20:51
     */
    
    #include <iostream>
    #include <string>
    #include <time.h>
    #include <GL/glu.h>
    #include <SDL2/SDL.h>
    #include <SDL2/SDL_opengl.h>
    #include <ctime> 
    #include <math.h>
    
    using namespace std;
    
    void CORE_LOG_Msg(int Level, string Msg, int Number = 0) {
        int CORE_log_level = 3; // 0 = DISABLED, 1 = Only errors (default), 2 = errors and warnings, 3 = errors, warnings and useless information
        if (Level <= CORE_log_level) {
            if (Level == 2) {
                Msg = "WARNING: " + Msg;
            }
            if (Level == 1) {
                Msg = "ERROR: " + Msg;
            }
            if (Level == 1) {
                if (Number == 0) {
                    cerr << Msg << endl;
                } else {
                    cerr << Msg << Number << endl;
                }
            } else {
                if (Number == 0) {
                    cout << Msg << endl;
                } else {
                    cout << Msg << Number << endl;
                }
            }
        }
        Msg = "";
        Number = 0;
    }
    
    template <typename Datatype>
    class ADT_List {
    public:
        struct Entry {
            Datatype content; //Content to save
            int ID;
            Entry *next; //Pointer to next entry
    
            Entry() {
                this->next = NULL;
                this->ID = -1;
                CORE_LOG_Msg(3,"A new ADT_List Entry has been created.");
            }
        };
    
        Entry Anf; //Create startentry
        Entry *Pos; //Create active position
    
        ADT_List() { //Constructor for List
            //Anf = new Entry();  //Create startentry
            this->Pos = &this->Anf; //Set active position to the first entry
            this->Anf.next = NULL; //Set next entry to NOT defined
            CORE_LOG_Msg(3,"A new ADT_List has been created.");
        }
    
        bool isEmpty() {
            if (this->Anf.next == NULL) { //Is the "first" entry empty?
                return true;
            } else {
                return false;
            }
        }
    
        void gotofirst() {
            this->Pos = &this->Anf; //Set active position to the start
        }
    
        void gotonext() {
            if(!this->isLast()) {
                this->Pos = this->Pos->next; //Set active position to the next
            } else {
                CORE_LOG_Msg(1,"Error. This is already the last entry.");
            }
        }
    
        void insert(Datatype x) {
            Entry *newEntry = new Entry(); //Prepare new entry
            newEntry->content = x; //Insert content for new entry
            newEntry->next = this->Pos->next; //Set next pointer of the new entry to the next entry of the active position
            this->Pos->next = newEntry; //Insert the new entry now
        }
    
        void insertID(Datatype x,int ID) {
            Entry *newEntry = new Entry(); //Prepare new entry
            newEntry->ID = ID; //Insert the wished ID
            newEntry->content = x; //Insert content for new entry
            newEntry->next = this->Pos->next; //Set next pointer of the new entry to the next entry of the active position
            this->Pos->next = newEntry; //Insert the new entry now
        }
    
        bool isLast(){
            return (this->Pos->next == NULL);
        }    
    
        Datatype getcontent(){
            return this->Pos->next->content;
        }
    
        int getID(){
            if(this->Pos->next->ID != -1) {
                return this->Pos->next->ID;
            }else {
                CORE_LOG_Msg(1,"Error. The ID is NULL.");
                return 0;
            }
        }
    
        void print() {
            cout << "Content of the ADT list:" << endl;
            while(!this->isLast()) {
                cout << "Entry: " << &this->Pos->next;
                cout << "       ID: " << this->Pos->next->ID;
                cout << "       Next is: " << this->Pos->next << endl;
                gotonext();
            }
            this->gotofirst();
            cout << "End." << endl;
        }
    
        bool select(int ID) {
            CORE_LOG_Msg(3,"Selecting...");
            while(!this->isLast()) {
                CORE_LOG_Msg(3,"Checking...");
                if(this->getID() == ID) {
                    return true;
                } else {
                    this->gotonext();
                }
            }
            return false;
        }
    };
    
    class World_Entry {
        /* INSERT HERE ATTRIBUTES: ID(^=List with structure data), MATERIAL;
         * FUNCTIONS TO CALL IF EVENT XY HAPPENS (created, died, damaged etc.)
         */
    };
    
    class World_Matrix {
    public:
        /* Templates for the dimensions:
         * ADT_List(World)<ADT_List(X-Axis)<ADT_List(Y-Axis)<ADT_List(Z-Axis)<ADT_List(Blocks)<World_Entry> > > > > *World = new ADT_List<ADT_List(X-Axis)<ADT_List(Y-Axis)<ADT_List(Z-Axis)<ADT_List(Blocks)<World_Entry> > > > >();
         * ADT_List(X-Axis)<ADT_List(Y-Axis)<ADT_List(Z-Axis)<ADT_List(Blocks)<World_Entry> > > > *X_Axis = new ADT_List<ADT_List(Y-Axis)<ADT_List(Z-Axis)<ADT_List(Blocks)<World_Entry> > > >();
         * ADT_List(Y-Axis)<ADT_List(Z-Axis)<ADT_List(Blocks)<World_Entry> > > *Y_Axis = new ADT_List<ADT_List(Z-Axis)<ADT_List(Blocks)<World_Entry> > >();
         * ADT_List(Z-Axis)<ADT_List(Blocks)<World_Entry> > *Z_Axis = new ADT_List<ADT_List(Blocks)<World_Entry> >();
         * ADT_List(Blocks)<World_Entry> *World_Entries = new ADT_List<ADT_List<World_Entry> >();
         */
    
        ADT_List<ADT_List<ADT_List<ADT_List<ADT_List<World_Entry> > > > > *World = new ADT_List<ADT_List<ADT_List<ADT_List<ADT_List<World_Entry> > > > >();
        //ADT_List<int> *X_Axis = new ADT_List <int>();
    
        World_Matrix() {
            CORE_LOG_Msg(3,"Created World matrix...");
        }
    
        SetBlockAt(int x, int y, int z, int ID) {
            CORE_LOG_Msg(3, "Trying to add a WORLD_Entry.");
            if(this->World->select(x)) {
                CORE_LOG_Msg(3,"Found the X-Axis-Entry.");
            } else {
                CORE_LOG_Msg(3,"No matching X-Axis-Entry found. Create one...");
                ADT_List<ADT_List<ADT_List<ADT_List<World_Entry> > > > *X_Axis = new ADT_List<ADT_List<ADT_List<ADT_List<World_Entry> > > >();
                this->World->insertID(X_Axis, x);
            }
        }
    };
    
    int main(int argc, char **argv) {
        CORE_LOG_Msg(3, "---- Program start now. ----");
    
        //Create World-Matrix
        CORE_LOG_Msg(3, "Initiate world matrix: WORLD");
        World_Matrix *WORLD = new World_Matrix();
        //WORLD->X_Axis->print();
        WORLD->SetBlockAt(0,0,0,0);
    
        [code]
    
        CORE_LOG_Msg(3, "---- Program have ended. ----");
        return 0;
    }
    

    Kompiler ausgabe:

    cd 'H:\OWNCLOUD\Entwicklung\NetBeansProjects\Spiel'
    H:\OWNCLOUD\MinGW\msys\1.0\bin\make.exe -f Makefile CONF=Debug
    "/H/OWNCLOUD/MinGW/msys/1.0/bin/make.exe" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
    make.exe[1]: Entering directory `/h/OWNCLOUD/Entwicklung/NetBeansProjects/Spiel'
    "/H/OWNCLOUD/MinGW/msys/1.0/bin/make.exe"  -f nbproject/Makefile-Debug.mk dist/Debug/MinGW-Windows/spiel.exe
    make.exe[2]: Entering directory `/h/OWNCLOUD/Entwicklung/NetBeansProjects/Spiel'
    mkdir -p build/Debug/MinGW-Windows
    rm -f "build/Debug/MinGW-Windows/main.o.d"
    g++    -c -g -std=c++14 -MMD -MP -MF "build/Debug/MinGW-Windows/main.o.d" -o build/Debug/MinGW-Windows/main.o main.cpp
    main.cpp: In member function 'int World_Matrix::SetBlockAt(int, int, int, int)':
    main.cpp:185:44: error: no matching function for call to 'ADT_List<ADT_List<ADT_List<ADT_List<ADT_List<World_Entry> > > > >::insertID(ADT_List<ADT_List<ADT_List<ADT_List<World_Entry> > > >*&, int&)'
                 this->World->insertID(X_Axis, x);
                                                ^
    main.cpp:104:10: note: candidate: void ADT_List<Datatype>::insertID(Datatype, int) [with Datatype = ADT_List<ADT_List<ADT_List<ADT_List<World_Entry> > > >]
         void insertID(Datatype x,int ID) {
              ^
    main.cpp:104:10: note:   no known conversion for argument 1 from 'ADT_List<ADT_List<ADT_List<ADT_List<World_Entry> > > >*' to 'ADT_List<ADT_List<ADT_List<ADT_List<World_Entry> > > >'
    make.exe[2]: *** [build/Debug/MinGW-Windows/main.o] Error 1
    make.exe[2]: Leaving directory `/h/OWNCLOUD/Entwicklung/NetBeansProjects/Spiel'
    make.exe[1]: *** [.build-conf] Error 2
    make.exe[1]: Leaving directory `/h/OWNCLOUD/Entwicklung/NetBeansProjects/Spiel'
    make.exe": *** [.build-impl] Error 2
    
    BUILD FAILED (exit value 2, total time: 46s)
    


  • void insertID(Datatype x,int ID)
    

    Ich sehe da keinen Pointer


Anmelden zum Antworten