stl - Weird bug while inserting into C++ std::map -


I'm trying to add some values ​​to the std :: map. In the first case, I get an indicator in the map, use it again and subscript operator to specify a value. I.e.

  (* foo) [index] = bar; Later, when I try to iterate over the collection, I return the key / value pair, which in all cases is zero for the value attribute (first. Map.begin ()) is the odd thing That if I merge through the combined function of the map, then everything is fine, that is:  
  foo-> Insert (std :: pair & lt; keytype, valueType & gt; (myKey, myValue));  

Why would this happen? Are not two methods functionally similar? I have pasted some snippets of the actual code for reference

  ... typedef std :: map & lt; Int, SCNode * & gt; SCNodeMap; ... Zero stem endcaly :: Hoskial nodes (SCNodmap * Chaknod) {(* Chakanodes) [root-> IID ()] = Route; SCNode * tmp = root- & gt; GetSucc (); While (tmp-> id =)! = Root-> id ()] {// (* chaknod) [tmp-> IID ()] == TMP; // crash (in the loop below) cycle nodes-> Insert (std :: pair & lt; int, SCNode * & gt; (tmp- & amp; getId (), tmp)); // OK std :: pair & lt; Int, SCNode * & gt; This = * (Cyclonode-> Find (TMP-> ID); Tmp = tmp-> GetSucc (); } // debugging; Print ID of all SCNode objects in the archive, std :: map & lt; Int, SCNode * & gt; :: Iterator = Chakanodes-> Start (); While (this! = Cycloneode-> end ()) {std :: pair & lt; Int, SCNode * & gt; P = (* this); SCNode * tmp = (* it) .second; // Skip Null = Chaknode-> Start () std :: cout & lt; & Lt; "TMP node ID:" & lt; & Lt; Tmp-> GetId () & lt;  

I am out of ideas Do you have any suggestions?

In your actual code you have:

  (* cyclone) [Tmp- & gt; GetId ()] == TMP;  

This will not specify the TM in the Mac, but rather in the context of creating a blank value in the map (see Neil Butterworth) - You have = = instead of = =. What do you want:

  (* Chaknodode) [tmp- & gt; GetId ()] = tmp;  

Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -