2016-02-18 45 views
-2

我有錯誤我窩時的結構的類獲取誤差爲嵌套結構中

此內部頭文件

class chord 
{ 
    public: 
    struct Node 
    { 
     void del(string, chord&); 
     void insert(string, chord&); 
    }; 
    map<int, Node>& getNodeList(); # line 44 
} 

這是錯誤消息:

44|error: candidate is: std::map<int, chord::Node>& chord::getNodeList()| 

這是.ccp文件

map<int, Node>& chord::getNodeList() # line 34 
{ 
    return Node_List; 
} 

當我嘗試編譯我收到以下錯誤

main.cpp|34|error: 'Node' was not declared in this scope 
main.cpp|34|error: template argument 2 is invalid| 
main.cpp|34|error: template argument 4 is invalid| 
main.cpp|34|error: prototype for 'int& chord::getNodeList()' does not match any in class 'chord'| 

當我更改爲以下類型,我得到這個錯誤

|35|error: invalid use of non-static data member 'chord::node'| 
|44|error: from this location| 

class chord 
{ 
    public: 
    struct Node 
    { 
     void del(string, chord&); 
     void insert(string, chord&); 
    }node; 
    map<int, node>& getNodeList(); 
} 

謝謝你的幫助是定義

+0

將'Node_List'類型的成員添加到您的'chord'類並使用該對象進行操作,而不是像現在這樣操作的類型 –

+1

請閱讀http://stackoverflow.com/help/mcve並根據需要更新您的問題。 –

回答

0

Nodechord裏面,所以當它在你的.cpp文件中看到map<int, Node>時,它找不到Node。把chord::也放在它的前面。

map<int, chord::Node>& chord::getNodeList() 

在你的第二個代碼片段,你聲明一個名爲nodeNode類型的成員對象,然後嘗試用它作爲模板類型參數。你想在你的第一個片段的語法。