내가 unordered_set에 요소를 삽입하려고 할 때이 오류를 받고 있어요에 유효하지 않은 피연산자 : 여기unordered_set : 이진 표현 ('const를 플레이'와 'const를 플레이')
error: invalid operands to binary expression ('const Play' and 'const Play')
{return __x == __y;}
은의 스크린 샷입니다 전체 오류 :이 내 해시 함수입니다 https://www.dropbox.com/s/nxq5skjm5mvzav3/Screenshot%202013-11-21%2020.11.24.png
: 나는이 unordered_list를 선언 곳
struct Hash {
size_t operator() (Play &play) {
unsigned long hash = 5381;
int c;
string s_str = play.get_defense_name() + play.get_offense_name() + play.get_description();
const char * str = s_str.c_str();
while ((c = *str++))
hash = ((hash << 5) + hash) + c; /* hash * 33 + c */
cout << hash << endl;
return hash;
}
};
입니다 :
unordered_set<Play, Hash> Plays;
그리고이 내 내 Play
클래스 ==
오버로드 : 여기에 갈 수 있는지
friend bool operator== (Play& p1, Play& p2)
{
return
(p1.get_defense_name() == p2.get_defense_name()) &&
(p1.get_offense_name() == p2.get_offense_name()) &&
(p1.get_description() == p2.get_description());
}
어떤 생각을?
감사합니다.
이'연산자의 서명을 변경하려고 ==''const'를 사용하는 CONST 다움을 추가하면 문제를 해결해야한다. 마찬가지로,'친구 bool 연산자 == (const Play & p1, const Play & p2)'. 논리 연산자가 비교 대상을 절대로 변경하지 않는 것이 좋습니다. –