D
Deepak
Hello,
I am working on a project where I am using the STL's "map"
datastructure inside a class that just acts as a container for the map
and manages it. The map a Key class to integers. The Key class just
has two variables of user defined types. I had implemented the key
comprarer structure that map requires like so:
struct KeyComparer
{
bool operator() (const Key & k1, const Key & k2) const
{
return ((k1.getA() < k2.getA()) &&
(k1.getB() < k2.getB()));
}
};
What i am finding is that whenever i use the maps internal functions
such as find(..) or insert(...) it doesnt work.
I have overloaded the '<', '==', and '=' operators, have copy
constructors/assignment operators defined.
It seems like the find() is just comparing one of the two components
of Key and therefore does not do the correct comparison even though i
defined the comparer.
The insert seems like it just doesnt insert beyond the first entry.
I would really appreciate if someone could provide me with insight as
to how to tackle this problem. Any help is appreciated.
Sincerely,
D
I am working on a project where I am using the STL's "map"
datastructure inside a class that just acts as a container for the map
and manages it. The map a Key class to integers. The Key class just
has two variables of user defined types. I had implemented the key
comprarer structure that map requires like so:
struct KeyComparer
{
bool operator() (const Key & k1, const Key & k2) const
{
return ((k1.getA() < k2.getA()) &&
(k1.getB() < k2.getB()));
}
};
What i am finding is that whenever i use the maps internal functions
such as find(..) or insert(...) it doesnt work.
I have overloaded the '<', '==', and '=' operators, have copy
constructors/assignment operators defined.
It seems like the find() is just comparing one of the two components
of Key and therefore does not do the correct comparison even though i
defined the comparer.
The insert seems like it just doesnt insert beyond the first entry.
I would really appreciate if someone could provide me with insight as
to how to tackle this problem. Any help is appreciated.
Sincerely,
D