Using HashSet
-
Hello, I want to use the latest collection classes from VC .NET so I chose
hash_set
. The collection is storing custom objects (not just plainint
s) that haveoperator <
. Can anyone show my how do define thehash_set
and its correspondinghash_compare
correctly? Thanks Best regards, Alexandru Savescu P.S. Interested in art? Visit this! -
Hello, I want to use the latest collection classes from VC .NET so I chose
hash_set
. The collection is storing custom objects (not just plainint
s) that haveoperator <
. Can anyone show my how do define thehash_set
and its correspondinghash_compare
correctly? Thanks Best regards, Alexandru Savescu P.S. Interested in art? Visit this!You only have to define
operator <
for your class:class MyClass
{
public:
...
bool operator<(const MyClass& x)const
{
// compare this and x
}
};Joaquín M López Muñoz Telefónica, Investigación y Desarrollo
-
You only have to define
operator <
for your class:class MyClass
{
public:
...
bool operator<(const MyClass& x)const
{
// compare this and x
}
};Joaquín M López Muñoz Telefónica, Investigación y Desarrollo
I wish it were that easy.... I get C2440 error (cannot convert from
const MyClass
tosize_t
). I think I must derive fromhash_compare
and implement custom hash method as the compiler does not know how to get a hash code for my objects... Best regards, Alexandru Savescu P.S. Interested in art? Visit this! -
I wish it were that easy.... I get C2440 error (cannot convert from
const MyClass
tosize_t
). I think I must derive fromhash_compare
and implement custom hash method as the compiler does not know how to get a hash code for my objects... Best regards, Alexandru Savescu P.S. Interested in art? Visit this!This sounds strange. Could you post the code to see how you're using
hash_set
? I think it should work once you definedoperator <
. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo -
This sounds strange. Could you post the code to see how you're using
hash_set
? I think it should work once you definedoperator <
. Joaquín M López Muñoz Telefónica, Investigación y DesarrolloHere's the code: #include #include using namespace std; class MyClass { public: int x; MyClass (int a) : x (a) { } bool operator < (const MyClass& OB) const { return x < OB.x; } }; int main () { hash_set MySet; MySet.insert (MyClass (2)); } Best regards, Alexandru Savescu P.S. Interested in art? Visit this!