나는 세트가 주문됨을 이해하므로 < 과부하가없는 오브젝트를 추가하면 작업자는 컨테이너를 정렬 된 상태로 유지하기 위해 더 작은 오브젝트를 말할 수 없습니다. 그러나, 왜 unordered_set으로 이것이 가능하지 않은지 나는 이해하지 못한다.C++ 11 : 왜 객체를 unordered_set에 저장할 수 없습니까?
나는 이런 식으로 뭔가하려고하면 :
c:\qt\qt5.1.0\tools\mingw48_32\lib\gcc\i686-w64-mingw32\4.8.0\include\c++\bits\hashtable_policy.h:1070: error: invalid use of incomplete type 'struct std::hash'
c:\qt\qt5.1.0\tools\mingw48_32\lib\gcc\i686-w64-mingw32\4.8.0\include\c++\bits\functional_hash.h:58: error: declaration of 'struct std::hash'
error: no matching function for call to 'std::unordered_set::unordered_set()'
c:\qt\qt5.1.0\tools\mingw48_32\lib\gcc\i686-w64-mingw32\4.8.0\include\c++\bits\hashtable_policy.h:1103: error: no match for call to '(const std::hash) (const someType&)'
c:\qt\qt5.1.0\tools\mingw48_32\lib\gcc\i686-w64-mingw32\4.8.0\include\c++\bits\stl_function.h:208: error: no match for 'operator==' (operand types are 'const someType' and 'const someType')
이유입니다 :
#include <iostream>
#include <string
#include <unordered_set>
using namespace std;
struct someType{
string name;
int code;
};
int main(){
unordered_set <someType> myset;
myset.insert({"aaa",123});
myset.insert({"bbb",321});
myset.insert({"ccc",213});
return 0;
}
내가 좋아하는 몇 가지 오류를 얻을 수 있습니까?
정확한 코드와 정확한 오류 메시지를 게시 할 수 있습니까? – templatetypedef
그것은 실제 오류가 아닐 것 같습니다. 실제로 '설정'을 사용하지 않으시겠습니까? –
아니요, 순서가 없습니다. 하지만 당신 말이 맞습니다. 정확한 오류는 아닙니다. 방금 전체 코드와 자세한 오류 메시지를 추가하기 위해 편집했습니다. 감사합니다 :) –