defining a hash set with a compare function
I am trying to do a very simple task of defining a new type of hash set which has a compare function as well.
using namespace std;
#include <iostream>
#include <ext/hash_set>
#include <hash_set>
#include <functional>
#include &开发者_高级运维lt;hash_compare>
typedef __gnu_cxx::hash_set<int, hash_compare<int, less<int> > > hashcomp;
int main(int argc, char * const argv[]) {
}
Error: hash_compare is not defined (line 7)
Error: expected unqualified-id before ">" token (line 7) Error: template argument 2 is invalid. (line 7)Seeing the error, I guess you haven't included <functional>
as you're using std::less<int>
in your code. I'm assuming that less<int>
in your code is actually std::less<int>
.
EDIT:
The error message clearly says
Error: hash_compare is not defined.
What else do you want? Include the header file which defines hash_compare
.
Your requirements are contradictory. A hash table has a random order, by definition.
精彩评论