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::mapname_, 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