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));
}
また、私はこの問題は、エラーメッセージからが何であるかを判断することはできません。ここで
はサンプルです:
note: candidate is:
note: size_t Hash::operator()(const Interval&)
note: candidate expects 1 argument, 2 provided
私が唯一の1つの引数を提供すると思った...
誰もが私の挿入コードの問題を参照してくださいしていますか?可能であれば、お手伝いをしてください。私はかなりの間、今のところ解決策を探していました。
編集:ここでは
は、新しいインスタンス生成コードです:しかし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 –