Visual Studioではなくgcc(WindowsとLinuxの両方)で使用しましたが、問題なく何度も使用しました。
実際の使い方については、ドキュメントはこちらです。
を使用して、予約するバケットの数を指定できます
void resize(size_type n)
識別子 Tに関する問題については、T という名前のテンプレート引数を実際の型に置き換えるのを忘れていると思います。わからない場合は、hash_map の使用方法のコード スニペットを貼り付けてください。
ドキュメントの例:
#include <hash_map>
#include <iostream>
struct eqstr
{
bool operator()(const char* s1, const char* s2) const
{
return strcmp(s1, s2) == 0;
}
};
int main()
{
std::hash_map<const char*, int, hash<const char*>, eqstr> months;
months["january"] = 31;
months["february"] = 28;
months["march"] = 31;
months["april"] = 30;
months["may"] = 31;
months["june"] = 30;
months["july"] = 31;
months["august"] = 31;
months["september"] = 30;
months["october"] = 31;
months["november"] = 30;
months["december"] = 31;
std::cout << "september -> " << months["september"] << endl;
std::cout << "april -> " << months["april"] << endl;
std::cout << "june -> " << months["june"] << endl;
std::cout << "november -> " << months["november"] << endl;
}
もちろん、必要に応じて char* の代わりに std::string を使用できます。
std::hash_map<std::string, int, hash<std::string>, eqstr> months;