CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Dec 2004
    Posts
    293

    Question 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.

  2. #2
    Join Date
    Apr 1999
    Posts
    50

    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;

  3. #3
    Join Date
    Dec 2004
    Posts
    293

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured