【发布时间】:2015-07-12 20:21:02
【问题描述】:
我正在尝试创建一个hash_set 来保存不同文件的名称,如下所示:
struct eq {
bool operator()(const char* c1, const char* c2) {
return strcmp(c1, c2) == 0;
}
};
int main(int argc, char* argv[])
{
hash_set<const char*, hash<const char*>, eq> fileNames;
return 0;
}
这给了我很多编译器错误:
Error 1 error C2039 : 'bucket_size' : is not a member of 'std::hash<const char *>' C : \Program Files(x86)\xDev\Microsoft Visual Studio 12.0\VC\include\xhash 264 1 Tests
Error 2 error C2065 : 'bucket_size' : undeclared identifier C : \Program Files(x86)\xDev\Microsoft Visual Studio 12.0\VC\include\xhash 264 1 Tests
Error 3 error C2039 : 'value_type' : is not a member of 'eq' C : \Program Files(x86)\xDev\Microsoft Visual Studio 12.0\VC\include\xmemory0 419 1 Tests
Error 4 error C2146 : syntax error : missing ';' before identifier 'value_type' C : \Program Files(x86)\xDev\Microsoft Visual Studio 12.0\VC\include\xmemory0 419 1 Tests
Error 5 error C4430 : missing type specifier - int assumed.Note : C++ does not support default - int C : \Program Files(x86)\xDev\Microsoft Visual Studio 12.0\VC\include\xmemory0 419 1 Tests
Error 6 error C2602 : 'std::allocator_traits<_Alloc>::value_type' is not a member of a base class of 'std::allocator_traits<_Alloc>' C :\Program Files(x86)\xDev\Microsoft Visual Studio 12.0\VC\include\xmemory0 419 1 Tests
Error 7 error C2146 : syntax error : missing ',' before identifier 'value_type' C : \Program Files(x86)\xDev\Microsoft Visual Studio 12.0\VC\include\xmemory0 242 1 Tests
Error 8 error C2065 : 'value_type' : undeclared identifier C : \Program Files(x86)\xDev\Microsoft Visual Studio 12.0\VC\include\xmemory0 242 1 Tests
Error 9 error C2059 : syntax error : '>' C : \Program Files(x86)\xDev\Microsoft Visual Studio 12.0\VC\include\xmemory0 242 1 Tests
...
【问题讨论】:
-
hash_set实际上是什么?您是否错过了在代码中包含某些内容? -
是的,我包括了:#include
。 hash_set 是我唯一能找到 Visual Studio 识别的东西。 -
你从哪里得到的?
hash_set不是标准的,所以它必须来自其他库。 C++11 的unorderd_set怎么样?如果不了解您的hash_set,我认为我们无能为力。 -
has_set是 Visual Studio 类型。我的猜测是,你想实际使用std::unordered_set -
请不要使用只包含文字的图片。它使得索引搜索和阅读视障人士变得更加困难。 FWIW,即使在现代显示器上,我也无法阅读上面的文字。
标签: c++ error-handling hashset