Maps and Class Objects

I have been having trouble with maps lately. My map has as a key an ip address and as its keyed element an object. When a unique ip is found, a new object is created and inserted into the map. However, when I go to print it, the keys print fine but each key refers to the last object inserted. I do not have the code on hand, but below is the basic construct. I have feeling that my class is missing something.

1
2
3
4
5
6
7
8
9
10
11
12
13
14

map<string, class instance> my map;  
if(mymap.find(ip_source) == mymap.end()) {

    class * add_obj = new class(param, param);

    mymap.insert(std::pair(ip_source, *add_obj);
} else {
    map<string, class instance>::iterator it;
    
    it->second.update_field = some_val;
}
 
 
I do not have the code on hand, but below is the basic construct.

That's would be a lovely memory leak and undefined behavior you had there... if it could be compiled.
Topic archived. No new replies allowed.