I wrote this LinkedList template class, which isn't finished yet- I have yet to add safety features and more methods. As of now it does what I need it to. But it fails in a certain situation and I don't know why.
template<class data_type> class LinkedList {
private:
    struct Node {
    data_type data;
    Node* prev;
    Node* next;
    Node() : prev(NULL), next(NULL) {}
};
Node* head;
Node* GetLastNode() {
    Node* cur = head;
    while (cur->next != NULL)
        cur = cur->next;
    return cur;
}
public:
LinkedList() {
    head = new Node;
    head->prev = head;
    head->next = NULL;
}
LinkedList(LinkedList<data_type> &to_copy) {
    head = new Node;
    head->prev = head;
    head->next = NULL;
    for (int i = 1; i <= to_copy.NumberOfItems(); i++) {
        this->AddToList(to_copy.GetItem(i));
    }
}
~LinkedList() {
    DeleteAll();
    delete head;
    head = NULL;
}
void AddToList(const data_type data) {
    Node* last = GetLastNode();
    Node* newnode = last->next = new Node;
    newnode->prev = last;
    newnode->data = data;
}
void Delete(const unsigned int position) {
    int currentnumberofitems = NumberOfItems();
    Node* cur = head->next;
    int pos = 1;
    while (pos < position) {
        cur = cur->next;
        pos++;
    }
    cur->prev->next = cur->next;
    if (position != currentnumberofitems)
        cur->next->prev = cur->prev;
    delete cur;
}
void DeleteAll() {
    Node* last = GetLastNode();
    Node* prev = last->prev;
    while (prev != head) {
        delete last;
        last = prev;
        prev = last->prev;
    }
    head->next = NULL;
}
data_type GetItem(unsigned int item_number) {
    Node* cur = head->next;
    for (int i = 1; i < item_number; i++) {
        cur = cur->next;
    }
    return cur->data;
}
data_type* GetItemRef(unsigned int item_number) {
    Node* cur = head->next;
    for (int i = 1; i < item_number; i++) {
        cur = cur->next;
    }
    return &(cur->data);
}
int NumberOfItems() {
    int count(0);
    Node* cur = head;
    while (cur->next != NULL) {
        cur = cur->next;
        count++;
    }
    return count;
}
};
I stated my problem in the question and here is an example:
class theclass {
public:
    LinkedList<int> listinclass;
};
void main() {
    LinkedList<theclass> listoftheclass;
    theclass oneclass;
    oneclass.listinclass.AddToList(5);
    listoftheclass.AddToList(oneclass);
    cout << listoftheclass.GetItem(1).listinclass.GetItem(1);
}
I can't figure out why it doesn't run right.
 
     
     
    