Click here to Skip to main content
15,892,537 members
Home / Discussions / ATL / WTL / STL
   

ATL / WTL / STL

 
AnswerRe: how do you sort a list? Pin
geo_m10-Jun-04 22:35
geo_m10-Jun-04 22:35 
GeneralRe: how do you sort a list? Pin
nm_11411-Jun-04 13:47
nm_11411-Jun-04 13:47 
GeneralRe: how do you sort a list? Pin
geo_m11-Jun-04 23:41
geo_m11-Jun-04 23:41 
GeneralRe: how do you sort a list? Pin
nm_11412-Jun-04 10:11
nm_11412-Jun-04 10:11 
GeneralRe: how do you sort a list? - Solution for VC6! Pin
T.T.H.3-Aug-04 5:06
T.T.H.3-Aug-04 5:06 
QuestionNested STL maps? Pin
dbunder9-Jun-04 16:00
dbunder9-Jun-04 16:00 
AnswerRe: Nested STL maps? Pin
10-Jun-04 4:10
suss10-Jun-04 4:10 
AnswerRe: Nested STL maps? Pin
Paul Ranson10-Jun-04 4:42
Paul Ranson10-Jun-04 4:42 
I converted your code into a small test program,
#include <map>
#include <string>

struct heapHeader
{
    std::string name_ ;
    int         id_ ;
    void *      p_ ;
} ;

struct heap
{
    std::map<std::string, std::map<int, heapHeader *> > s_heaps ;

    bool insert ( heapHeader *header)
    {
        std::map<int, heapHeader *> tmpMap;
        std::pair< std::map<std::string, std::map<int, heapHeader *> >::iterator, bool> p;

        tmpMap.insert(std::pair<int, heapHeader *>(header->id_, header));
        p = s_heaps.insert(std::pair<std::string, std::map<int, heapHeader *> >(header->name_, tmpMap));
        
        return p.second ;
    }
} ;

int main( )
{
    heap h ;
    heapHeader * ph = new heapHeader ;
    ph->id_ = 0 ;

    h.insert ( ph ) ;

    return 0;
}

and it compiles and runs as expected. So I don't know what your problem is.

However I think your code is wrong. In the first place I wouldn't use a map where the key is embedded in the type, a set would be more efficient, you can create specific predicates to allow the object to be sorted according to its id or name. Secondly what if you insert a subsequent heapHeader with the same name? I assume this is legal? This way your maps of id-heapheader would have more than one member.

Anyway I would consider rewriting 'insert' along these lines,
    void insert ( heapHeader *header)
{
    std::pair< std::map<std::string, std::map<int, heapHeader *> >::iterator, bool> ;

    p = s_heaps.insert(std::make_pair<std::string, std::map<int, heapHeader *> >(header->name_, std::map<int, heapHeader *> ()));
    (*p.first).second.insert ( std::make_pair ( header->id_, header )) ;
}


Although perhaps the syntax could be tidied. The point is that std::map::insert never fails (other than through memory exhaution, in which case it throws an exception), it either inserts a new entry and returns 'true' in the second part of the pair, or returns false. In either case the first part of the return is an iterator to the appropriate entry.

Hope that made some sense.

Paul
GeneralCreateImage problem in java Pin
sriamar8-Jun-04 6:19
sriamar8-Jun-04 6:19 
GeneralCSMTPConnection Authentication Pin
prasoon997-Jun-04 18:37
prasoon997-Jun-04 18:37 
GeneralRe: CSMTPConnection Authentication Pin
Mike Dimmick8-Jun-04 2:16
Mike Dimmick8-Jun-04 2:16 
GeneralSome WTL - to MFC conversion help Pin
Ajnstajn6-Jun-04 23:25
Ajnstajn6-Jun-04 23:25 
GeneralRe: Some WTL - to MFC conversion help Pin
Jason De Arte7-Jun-04 8:39
Jason De Arte7-Jun-04 8:39 
Questionhow to read from or write to a file in c++? Pin
lzh086-Jun-04 15:21
lzh086-Jun-04 15:21 
AnswerRe: how to read from or write to a file in c++? Pin
Derick Cyril Thomas6-Jun-04 16:55
Derick Cyril Thomas6-Jun-04 16:55 
GeneralComposite and Builder Dessign Patterns Pin
Arun AC6-Jun-04 7:29
Arun AC6-Jun-04 7:29 
GeneralRe: Composite and Builder Dessign Patterns Pin
valikac6-Jun-04 12:47
valikac6-Jun-04 12:47 
GeneralMenu Ownerdraw and WindowFromDC Pin
Derick Cyril Thomas6-Jun-04 2:28
Derick Cyril Thomas6-Jun-04 2:28 
GeneralRe: Menu Ownerdraw and WindowFromDC Pin
Jason De Arte6-Jun-04 14:14
Jason De Arte6-Jun-04 14:14 
GeneralRe: Menu Ownerdraw and WindowFromDC Pin
Derick Cyril Thomas6-Jun-04 16:50
Derick Cyril Thomas6-Jun-04 16:50 
Questionhow to use WTL in other IDE,e.g bc++? Pin
lzh085-Jun-04 22:51
lzh085-Jun-04 22:51 
GeneralActiveXcontrol with directX in clientwindow , how prevent drawing background color Pin
Vliegenthart5-Jun-04 0:40
Vliegenthart5-Jun-04 0:40 
GeneralATL experts, help! Navigating to a new page in an ATL Active X control Pin
mcase4-Jun-04 22:44
mcase4-Jun-04 22:44 
GeneralRe: ATL experts, help! Navigating to a new page in an ATL Active X control Pin
Jason De Arte6-Jun-04 7:28
Jason De Arte6-Jun-04 7:28 
GeneralGreat advice! Pin
mcase6-Jun-04 22:45
mcase6-Jun-04 22:45 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.