STL - std::map question...
Hi.
I declare this kind of map:
typedef std::map<const char*, ISingleWord*> DataStructure;
DataStructure m_dsSharedWords;
and when I use the 'find()' method it doesn't return good answers, I understand it's because I need to implement some kind of function that is like 'Comparator' in java (implemets 'less <') something like that...
the declaration should be (I think):
typedef std::map<const char*, ISingleWord*, Comparator> DataStructure;
and then I need to implement 'Comparator' ...is that the way ??
If someone can show me some piece of code...it would be appreciated.
Thanks.
Re: STL - std::map question...
If you want to manage your strings outside the map, the comparator would look like:
Code:
bool Comparator(const char* x, const char* y)
{
return strcmp(x, y) < 0;
}
You may find it easier to use std::string instead of const char*, and this may let you off defining a comparator:
Code:
typedef std::map<std::string, ISingleWord*> DataStructure;
Re: STL - std::map question...
Thank for answering Andrew ...
Another question, If my map is in some class I also put the Comparator method in the class as a function member of the class?
and the creation of the map should look like:
typedef std::map<const char*, ISingleWord*, Comparator> DataStructure;
??
Thanks.