2016-09-29 30 views
5

Bir Setİkili Ağacı Arabirimi dayalı çalışıyorum çalışıyorum. Bu nedenle, kök (Düğüm işaretçisi) ile başlayan bu kümeyi yapıyorum, burada Node bir değer, sağ ve sol çocuk (Düğüm için işaretçiler de vardır). Böylece, kök düğümün sağında yeni bir düğüm oluşturabilirim. tanımları bir göz atın: Bu hata ile ilgili mesajların çok gördüm, ama bunların çoğu yazılı kaynaklandığınıNesne bir türü adı değil - C++

/home/jscherman/ClionProjects/algo2-t3-bts/set.hpp:247:1: error: ‘Node’ does not name a type 
Node & Set<T>::fatherOfNode(const Node & root, const T & key, const bool hook) const { 
^ 

:

template <class T> 
class Set 
{ 
    public: 
     Set(); 
     ~Set(); 
     void push(const T&); 
     bool belongs(const T&) const; 
     void remove(const T&); 
     const T& min() const; 
     const T& max() const; 
     unsigned int cardinal() const; 
     void show(std::ostream&) const; 

     friend ostream& operator<<(ostream& os, const Set<T> &c) { 
      c.show(os); 
      return os; 
     } 

    private: 

     struct Node 
     { 
      Node(const T& v); 
      T value; 
      Node* left; 
      Node* right; 
     }; 

     Node* root_; 
     int cardinal_; 

    Node & fatherOfNode(const Node & root, const T & key, const bool hook) const; 

}; 

... 

// This function is the one with errors. 
template <class T> 
Node & Set<T>::fatherOfNode(const Node & root, const T & key, const bool hook) const { 
    // Some code 
} 

Yani ben bu hatayı yaşıyorum uygulamalarını tanımlarından önce işler. Gördüğünüz gibi, fatherOfNode'un uygulanması, tanımının altındadır, bu yüzden benim durumum gibi görünmüyor.

Neler olup bittiği hakkında bir fikrin var mı?

template <class T> 
typename Set<T>::Node & Set<T>::fatherOfNode(const Set<T>::Node & root, const T & key, const bool hook) const { 

Here it is, working.

:

Set<T>::Node 

Yani fonksiyon tanım olması gerekir: Birlikte bu sorunu çözmek için gereken bu sınıfın dışında böylece

+2

' :: Node' ayarlanmış olmalıdır. –

+0

Sorunun nesi yanlış? Sanırım yeterince spesifik ve açıkım. Bana neyi yanlış yaptığımı söyler misin, böylece gelecekte tekrarlamayacağım? – jscherman

cevap

4

Node

, Set bir iç sınıftır
+0

Ohhhh Bunu "typename" olmadan denedim. Teşekkürler! – jscherman