2013-04-13 145 views
1

請向我解釋此方法的聲明/說明中的錯誤?函數聲明有什麼錯誤?

class Set 
{ 
    struct Node { 
     // ... 
    }; 
    // ... 
    Node* &_getLink(const Node *const&, int) const; 
    // ... 
}; 

Node* &Set::_getLink(const Node *const &root, int t) const 
{ 
    // ... 
} 

我沒有看到錯誤,但編譯器(MS VS C++)給出了很多語法錯誤。

+0

嘗試設置::節點到你的代碼 –

+0

什麼是編譯器錯誤?把它放在問題標題中。 –

回答

3

你忘了完全限定的Node名稱(這是在Set範圍定義):

Set::Node* &Set::_getLink(const Node *const &root, int t) const 
// ^^^^^ 

沒有充分的資格,編譯器會尋找名爲Node一個全球性的類型,它不存在。

0

問題是一個範圍。你需要在這裏前綴Node

Set::Node* &Set::_getLink(const Node *const &root, int t) const 
{ 
    // ... 
} 

事實上,Node是它遇到的時間(你是在命名空間內,而不是內部Set的範圍)未知。您還可以使用auto

auto Set::_getLink(const Node *const &root, int t) const -> Node *& 
{ 
    // ... 
} 

->後,你在Set的範圍和Node是已知的。

0

你不要在全局範圍內定義節點
所以用這個代碼

//by Set::Node we give compiler that this function exist in class Node 
Set::Node* &Set::_getLink(const Node *const &root, int t) const 
{ 
    // ... 
}