A
asterixgallier
hello
i have a simple (?) problem using maps with my own type for the key.
i have used a struct overloading the < operator, but if i search (using
find) with a key, that does not exists in the map, i get anexisting
key/value pair from the map.
i have tried something like this:
struct MyKey {
public:
MyKey(
unsigned short key1,
unsigned long key2)
:key1(key1),
key2(key2) {}
bool operator<(MyKey const& scnd) const {
return (
key1<scnd.key1 &&
key2<scnd.key2);
};
private:
unsigned short key1;
unsigned long key2;
};
class MyValue {
....
}
std::map <MyKey, MyValue*> MyValueList;
any ideas? tutorials? code examples?
thanks & with regards
asterix
i have a simple (?) problem using maps with my own type for the key.
i have used a struct overloading the < operator, but if i search (using
find) with a key, that does not exists in the map, i get anexisting
key/value pair from the map.
i have tried something like this:
struct MyKey {
public:
MyKey(
unsigned short key1,
unsigned long key2)
:key1(key1),
key2(key2) {}
bool operator<(MyKey const& scnd) const {
return (
key1<scnd.key1 &&
key2<scnd.key2);
};
private:
unsigned short key1;
unsigned long key2;
};
class MyValue {
....
}
std::map <MyKey, MyValue*> MyValueList;
any ideas? tutorials? code examples?
thanks & with regards
asterix