2011-04-07 41 views
0

我正在尝试做一个非常简单的定义具有比较函数的新类型散列集的任务。定义具有比较函数的散列集

using namespace std; 
#include <iostream> 
#include <ext/hash_set> 
#include <hash_set> 
#include <functional> 
#include <hash_compare> 
typedef __gnu_cxx::hash_set<int, hash_compare<int, less<int> > > hashcomp; 

int main(int argc, char * const argv[]) { 

} 

错误:hash_compare没有定义(第7行)
错误:前 “>” 令牌(第7行)预期不合格-ID
错误:模板参数2是无效的。 (第7行)

+0

@Pegah:你为什么不用线号发布错误信息......并且还要提及哪一行对应哪一段代码...... – Nawaz 2011-04-07 17:00:32

+0

以前是空间还是:: intentional? – 2011-04-07 17:02:07

+0

@Alexei Sholik的空间不是故意的。删除它。还是一样的错误。 – Pegah 2011-04-07 17:04:32

回答

1

看到错误,我想你没有包含<functional>,因为你在代码中使用std::less<int>。我假设您的代码中的less<int>实际上是std::less<int>

编辑:

错误消息明确表示

Error: hash_compare is not defined.

你想要做什么?包含定义为hash_compare的头文件。

+0

@Nawaz我加了:#include 但仍然是一样的错误。 – Pegah 2011-04-07 16:39:07

+0

@Pegah:使用'std :: less '而不是'less '。 – Nawaz 2011-04-07 16:40:12

+0

@Nawaz using namespace std; #include #include typedef __gnu_cxx :: hash_set 现在是这样,但仍然是相同的错误。 – Pegah 2011-04-07 16:42:23

0

您的要求是矛盾的。根据定义,哈希表具有随机顺序。

+0

这意味着无法对hash_set进行排序? – Pegah 2011-04-07 17:41:30

+0

不是。散列管理强加它自己的顺序(这不是你可能想要的任何东西)。 – 2011-04-07 18:41:13

+0

感谢您的回答。 – Pegah 2011-04-07 19:05:11