다음 코드를 사용하여 unordered_set<Interval>
을 만듭니다. 이것은 잘 컴파일됩니다. 이 코드를 사용하여 삽입 할 때사용자 지정 해시 함수를 사용하여 unordered_set에 삽입
struct Interval {
unsigned int begin;
unsigned int end;
bool updated; //true if concat. initially false
int patternIndex; //pattern index. valid for single pattern
int proteinIndex; //protein index. for retrieving the pattern
};
struct Hash {
size_t operator()(const Interval &interval);
};
size_t Hash::operator()(const Interval &interval){
string temp = to_string(interval.begin) + to_string(interval.end) + to_string(interval.proteinIndex);
return hash<string>()(temp);
}
unordered_set<Interval, string, Hash> test;
그러나, 나는 컴파일 할 수 없습니다 :
for(list<Interval>::iterator i = concat.begin(); i != concat.end(); ++i){
test.insert((*i));
}
또한, 나는 문제가 오류 메시지에서 무엇인지 확인할 수 없습니다. 나는 단지 1 개 인자를 제공하는 생각
note: candidate is:
note: size_t Hash::operator()(const Interval&)
note: candidate expects 1 argument, 2 provided
...
사람이 내 삽입 코드에 문제가 있음을 볼 수 있습니까 : 여기
는 샘플입니다? 가능한 한 도와주세요. 저는 지금 꽤 오랫동안 해결책을 찾고있었습니다.편집 :
여기 새로운 인스턴스 코드입니다 :unordered_set<Interval, Hash> test;
는 그러나, 나는 여전히 오류 메시지의 슬루를 수신하고 있습니다. 예 :
note: candidate is:
note: size_t Hash::operator()(const Interval&) <near match>
note: no known conversion for implicit ‘this’ parameter from ‘const Hash*’ to ‘Hash*’
내 대답이 업데이트되었습니다. 수정 내용에서 설명하는 문제가 해결되어야합니다. –
http://stackoverflow.com/questions/17016175/c-unordered-map-using-a-custom-class-type-as- the-key –