0

Im trying to create a double linked list. With a link to Head and a link to the tail. I wrote my Member functions in the liste.cpp (German for list and liste.hpp. There I also included the Node class I thought I did everything right and checked if I maybe declared the functions differently. The Code includes a destructor method, a =operator and a destructor on the Node and list class. I get the error:

"Undefined symbols for architecture x86_64:
  "Liste::n_Hentry(int)", referenced from:
      _main in main-47ad3c.o
  "Liste::n_Tentry(int)", referenced from:
      _main in main-47ad3c.o
  "Liste::Liste(int)", referenced from:
      _main in main-47ad3c.o
  "Liste::~Liste()", referenced from:
      _main in main-47ad3c.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)"

I've read the answer, that my member methods aren't matching but that's not the case here..

My Code:

list.cpp

#include"liste.hpp"
#include<iostream>

Liste::Liste(int data){
    this->head = new Node;
    this->tail = head;
    this->head->data = data;
};
Liste::~Liste(){
    Node *current;
    while(this->head->next != nullptr){
        current = this->head->next;
        delete head;
        this->head = current;
    }
    delete current;
}
void Liste::n_Tentry(int data){
    Node *current;
    if(tail == head){
        this->tail = new Node;
        this->head->prev = this->tail;
        this->tail->next = head;
    }else{
        
        this->tail->prev = new Node;
        current = this->tail;
        this->tail = this->tail->prev;
        this->tail->next = current;
    }
    this->tail->data = data;
    delete current;
}
void Liste::n_Hentry(int data){
     Node *current;
    if(tail == head){
        this->head = new Node;
        this->head->prev = this->tail;
        this->tail->next = this->head;
    }else{
        this->head->next = new Node;
        current= head;
        this->head = this->head->next;
        this->head->prev = current;
    }
    this->head->data =data;
    delete current;
}

liste.hpp

#include<iostream>
class Node{
    public:
        Node *next;
        Node *prev;
        int data;
        Node():next(nullptr),prev(nullptr),data(0){std::cout << "Konstruktor Node" << std::endl;};
        Node(Node *next, Node *prev, int data)
            {
                this->next = next;
                this->prev = prev;
                this->data = data;
                std::cout << "Konstruktor Node mit Daten" << std::endl;
            }
        Node(const Node& source) 
        {
            this->next = source.next, 
            //eigentlich überflüssig bis jetzt?
            this->prev = source.prev, 
            this->data = source.data;
            std::cout << "Copy Konstruktor Node" << std::endl;
        }
        Node& operator=(const Node& source)
        {
        //Prüft eigene Adresse mit Source Adresse
            if (this != &source)
                {   
                    //Löscht Zuweisungen in diesem Fall Nullpointer
                    delete this->next;
                    delete this->prev;
                    //Weist neue Daten zu sprich erstellt eine gesamte Kopie
                    this->data = source.data;
                    this->next = new Node(source.next,source.prev,source.data); 
                }
                std::cout << "Operator Konstruktor Node" << std::endl;
                return *this;
                }
        //wann wird dieser genau Aufgerufen?
        ~Node(){
            delete this->next;
            delete this->prev;
        };    
};
class Liste{
    private:
        Node *head;
        Node *tail;
    public:
        Liste(int data);
        ~Liste();
        void n_Tentry(int data);
        void n_Hentry(int data);
        int ret_head();
        int search();
        int ret_tail();
};

main.cpp

#include"liste.hpp"

int main(){
    Liste a = 10;
    a.n_Hentry(40);
    a.n_Tentry(100);
    return 0;
}
cycy1234
  • 5
  • 1

0 Answers0