
30 Nov
2011
30 Nov
'11
12:31 p.m.
<...>
public: V& operator[]( const K& key ) { r = new mutable_pair(key,V()); c.insert(c.end(),*r); return (*r).second; } <..> I now correctly get two iterators, but in this class don't work the assignment: my output is: Joe - 0 Lillo - 0 Mary - 0
Of course, because insert() copies its parameter, so you actually return the ref to the original object while the container stores its copy (thus you also have a memory leak). The code should be as follows: V& operator[]( const K& key ) { c.insert(c.end(), mutable_pair(key,V())); return c.get<1>().find(key)->second; }