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;
}
그러나, 내가 대신 *itr
의 itr
(반복자)를 반환 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
에 의해 정의 된 반복자 형식을 반환하고자합니다.
다른 모든 사람들은 잘 모릅니다. 그러나 [자체 포함 된 예] (http://sscce.org/#selfcon)를 통해 어떤 일이 일어나는지 알 수 있습니다. – Dukeling