2016-09-17 74 views
0

可視化
NTlist:[NTstring,RHSlist] < - > [NTstring,RHSlist] < - > [NTstring,RHSlist] ...C++列表迭代不訪問列表的內容

Ntlocation「點」,比如說,中間鏈接^(上面),因爲這裏的NTstring匹配我正在搜索的內容。

我想要做什麼:
使用NTlocation 「指針」 我想訪問和修改此處的RHSlist。

問題:
Debugger shows RHSlist data being put into NTlocation

But I want RHSlist data to be in element of NTlist

非常感謝您的幫助!

編輯。每個請求添加代碼。再次感謝!

typedef struct RHSnode { 
    token_type type; 
    string token; 
} RHSnode; 

typedef struct NTnode { 
    token_type type; 
    string token; 
    list<RHSnode> RHSlist; 
} NTnode; 

int function { 
    list<NTnode> NTlist; 
    list<NTnode>::iterator NTlocation; 

    freopen("example.txt", "r", stdin); 
    t_type = getToken(); //this function gets tokens from txt file above 
    // code has been simplified for your viewing pleasure 
    // but basically NT.list is created for each token listed at start of 
    // text file in the following manner. (This works fine) 
    NTnode entry; 
    entry.token = string(current_token); 
    NTlist.push_back(entry); 
    t_type = getToken(); 

    // loop until all tokens are read 
    { 
    t_type = getToken(); 
    string NTstring = string(current_token); 
    NTlocation = searchNTList(NTstring, NTlist); 

    RHSnode entry; 
    entry.token = string(current_token); 

    //****Here is the problem: 
    NTlocation->RHSlist.push_back(entry);    

    } 

    return 1; 
} 

list<NTnode>::iterator searchNTList(string NTstring, list<NTnode> &NTlist){ 
    list<NTnode>::iterator NTlocation = NTlist.end(); //"past-the-end"  indications search failure 
    list<NTnode>::iterator iterator = NTlist.begin(); 

    for (; iterator != NTlist.end() ; iterator++){ 

    if (iterator->token.compare(NTstring) == 0){ 
     NTlocation = iterator; 
     break; 
    } 

    } 
    return NTlocation; 
} 
+1

顯示代碼,散文是徒勞! –

+0

你的問題中也有大量的代碼。你的問題是否有必要?你能把它縮小到還能再現問題的最小量嗎? –

+0

@BillLynch感謝您查看代碼。它已被簡化。很尊重你,先生。 – mtnMan

回答

1

最低限度:

list<NTnode>::iterator searchNTList(string NTstring, list<NTnode> NTlist){ 

這將返回一個迭代器的NTlist本地副本。你可能想通過const引用傳遞NTlist