このリンクリストクラスをC++で作成しましたが、実行した後、プログラムが応答しなくなる場合を除いて、正常に動作します。問題の原因となっている回線を特定しましたが、理由がわかりません。別の方法で入力しても同じことをします。
これが私のリストクラスです:
#include <string>
 template<class T>
 class List : public Object{
private: 
    Node<T>* first;
    Node<T>* last;
    int length;
public:
    List() : Object(new std::string("List")) {
        first = NULL;
        last = NULL;
        length = 0;
    }
    ~List() {
        delete first;
        delete last;
    }
    void Add(T value) {
        if(first==NULL)
            first = new Node<T>(NULL, value);
        else if(last==NULL)
            ---->last = new Node<T>(first, value);<-----
        else
            last = new Node<T>(last, value);
        length++;
    }
    T Remove(T value) {
        Node<T>* temp = first;
        while(temp!=NULL) {
            if(temp->GetValue()==value) {
                temp->GetPrev()->SetNext(temp->GetNext());
                temp->GetNext()->SetPrev(temp->GetPrev());
                delete temp;
                length--;
                return value;
            }
            temp = temp->GetNext();
        }
        return 0;
    }
    T Get(int index) {
        Node<T>* temp = first;
        int i = 0;
        while(temp!=NULL) {
            if(i==index)
                return temp->GetValue();
            i++;
            temp = temp->GetNext();
        }
        return 0;
    }
 };
プログラムの上のマークされた行を削除すると、応答しなくなります。これは私のノードコンストラクターです:
#include <string>
template<class T>
class Node : public Object{
private:
    Node* next;
    Node* prev;
    T value;
public:
    Node(Node* prev, T value) : Object(new std::string("Node")){
        if(prev!=NULL) {
            prev->next = this;
            this->prev = next;
        } 
        next = NULL;
        this->value = value;
    }
    ~Node() {
        delete next;
    }
    T GetValue() {
        return value;
    }
    Node* GetNext() {
        return next;
    }
    Node* GetPrev() {
        return next;
    }
};
私のオブジェクトクラス:
#include <string>
class Object {
private:
    std::string* type;
public:
    Object() {
        type = new std::string("Object");
    }
    Object(std::string* type) {
        this->type = type;
    }
    ~Object() {
        delete type;
    }
    std::string* GetType() {
        return type;
    }
};
私のTest.cpp
#include <iostream>
#include <string>
#include "Object.h"
#include "Node.h"
#include "List.h"
using namespace std;
int main () {
List<int> l;
l.Add(5);
l.Add(93);
l.Add(17);
l.Add(7789);
l.Add(60);
cout << "node 4 is:" << l.Get(3) << endl;
return 0;
}
エラー画像http://i50.tinypic.com/2mw5phi.png 読んでくれてありがとう。できるだけ早く助けてください。もっと情報が必要な場合はコメントしてください。