ですから、なぜこれが起こっているのか、私は本当にイライラしています。std::string に似たクラスを実装していますが、これは配列の代わりにリンク リストを使用しています。私のオーバーロードされた演算子 = は、奇妙な理由で機能していません。以下に示すように、メソッド内でポインターを出力すると文字列がリンク リストにコピーされますが、このポインターを返す文字列オブジェクトを作成すると、コンソールに無限のジャンクが出力されます。ここで何が欠けているかについてのアイデアはありますか? (関連するコードのみを貼り付けています)
static int NumAllocations = 0;
struct ListNode {
    char info;
    ListNode *next;
    ListNode () : info('0'), next(0) {}
    ListNode ( char c ) : info (c), next(0) {}
};
class MyString {
 private:
    ListNode *head;
    static void delstring (ListNode *l);
    static int strlen (ListNode * head);
    static ListNode* strcpy (ListNode *dest, ListNode *src);
 public:
MyString::MyString () : head(0) {}
MyString::MyString (ListNode *l) : head(l) {}
MyString::MyString( const MyString & s ) {
    if (s.head == 0)
        head = 0;
    else
        head = strcpy(head, s.head);
}
MyString MyString::operator = (const MyString & s ){               
    ListNode *renew = NULL;
    if (head != s.head) {
        if (head != 0)
            delstring(this -> head);
        head = strcpy(head, s.head);
        // printList(head); (this prints out the string just fine, so it must be the                                   constructor ? but what about it ?!
        MyString res (head);
        return res;
    }
}
MyString::~MyString(){
    if (head == 0)
        return;
    ListNode *temp = NULL;
    do {
        temp = head -> next;
        delete head;
        -- NumAllocations;
        head = temp;
    } while (temp != 0);
}
静的パブリック関数
ListNode* MyString::strcpy (ListNode *dest, ListNode *src){
    dest = new ListNode (src -> info);
    ++ NumAllocations;
    ListNode *iter = dest;
    for (ListNode *ptr = src -> next; ptr != 0; ptr = ptr ->next){
        iter -> next = new ListNode (ptr -> info);
        iter = iter -> next;
        ++ NumAllocations;
    }
    return dest;
}
void MyString::delstring (ListNode *l){
    if (l == 0)
        return;
    ListNode *temp = NULL;
    do {
        temp = l -> next;
        delete []l;
        -- NumAllocations;
        l = temp;
    } while (temp != 0);
    l = 0;
}