2013-05-18 7 views
0

추상 해시 테이블 컨테이너를 구현하고있었습니다.반복자를 반환하는 방법 - :: iterator를 함수 반환 값으로 반환

template <class HashedObj> 
HashedObj& HashTable<HashedObj>::find(const HashedObj &x){ 
    typename list<HashedObj>::iterator itr; 
    itr = std::find(theList[hash(x)].begin(), theList[hash(x)].end(), x); 
    if(itr == theList[hash(x)].end()) 
     return ITEM_NOT_FOUND; 
    else 
     return *itr; 
} 

그러나, 내가 대신 *itritr (반복자)를 반환 findAddress()라는 다른 함수를 정의하려면 : 아래 그림과 같이 내 find() 기능이 제대로 정의와 잘 작동한다. 내 코드는 다음과 같습니다

typedef list<HashedObj>::iterator iterator; 
template <class HashedObj> 
iterator HashTable<HashedObj>::find(const HashedObj &x){ 
    return std::find(theList[hash(x)].begin(), theList[hash(x)].end(), x); 
} 

가 위의 것을 불평 할 것이다 :

type std::list<HashedObj, std::allocator<_CharT> > is not derived from type 
    HashedTable<HashedObj>. 

은 기본적으로 내가 전에 std에 의해 정의 된 반복자 형식을 반환하고자합니다.

+0

다른 모든 사람들은 잘 모릅니다. 그러나 [자체 포함 된 예] (http://sscce.org/#selfcon)를 통해 어떤 일이 일어나는지 알 수 있습니다. – Dukeling

답변

0

저는 전문가는 아니지만 두 매개 변수 모두 동일한 코드를 허용하면서 주어진 코드에서 동일한 이름을가집니다. 이게 정상인가? 또한 "findAddress()"클래스 대신 "findAddress()"이라는 함수를 사용한다고 가정합니다.