2014-12-03 2 views
0

이중 매개 변수 이진 검색 트리를 개발했으며이를 사전 적용에 적용하려고합니다. 그러나 트리 내에서 내 find 함수는 필자가해야만 하듯이 작동하지만 사전 클래스의 내부에서 호출 할 때 컴파일러 오류 "예상 기본 표현식이 '>'토큰이됩니다."라는 오류가 발생합니다. 아무도 무슨 일이 일어나고 있는지 이해할 수있게 도와 줄 수 있습니까? 다른 파일에서 함수를 호출하는 데 익숙하지 않습니다.다른 헤더 파일에서 함수를 호출 할 때 오류 발생 (C++)

이것은 bst.h

V & find (K key)      
    { 

    TreeNode<K,V> *traverseFind; 

    traverseFind = root; 
    unsigned int compareTraverseToHeight = 0; 

    while (compareTraverseToHeight < heightCount) 
    { 
     if (traverseFind == NULL) // Fallen off 
     { 
      keyFinder = 0; 
      break; 

     } 

     else if (key == traverseFind->key)// Found key 
     { 
      keyFinder = 1; 
      break; 
     }  

     else if (key < traverseFind->key)     
     {             . 
      traverseFind = traverseFind->left; 
     } 


     else 
     { 
      traverseFind = traverseFind->right; 
     } 


     compareTraverseToHeight++;  

    } // end of loop 


      if(keyFinder ==0) 
      { 
       throw key_not_found_exception(); 

      } 


     cout<<"RETURNED "<<traverseFind->value<<endl; 

     return traverseFind->value; 

} 

의 내부 이진 검색 트리에서 나의 찾기 기능입니다 그리고 사전 :

#include bst.h 

    template <class K, class V> class Dictionary 
    { 
    public: 

     BinarySearchTree<K,V> wiktionary; 

     Dictionary() 
     { 
     } 

     ~Dictionary() 
     { 
     } 

    V & find (K key) 
    { 

     return(wiktionary.find(<V>)); //this is the issue 

    } 



    private: 


    }; 

    #endif 

그리고 메인에서 응용 프로그램 :

int main() 
{ 

    Dictionary<string, int> d; 
    int val = d.find("abc"); 
    if (val != 15) 
     throw dictionary_tester_exception(__FILE__, __LINE__); 

    return 0; 

} 
+0

사용'wiktionary.find'(키) :/ –

+0

오 와우, 나는 그것을 잡을하지 않았다 방법을 모르겠어요. 이 대답을하면 받아 들일거야, 고마워. – Mock

답변

0

문제는 <V>이 템플릿 인수를 지정하지만 사용자가에 전달하려고 시도하는 것입니다. 함수 인수로 대신. find 멤버 함수는 템플리트 화되지 않으므로 템플릿 인수로 전달하려고해도이 함수는 작동하지 않습니다. 당신이 좋아하는 find에 인수로 key을 통과해야 제공된 코드를 기반으로 그렇게

return(wiktionary.find(key)); 
관련 문제