Note that there are some explanatory texts on larger screens.

plurals
  1. POdeleting elements completely from multimap (C++)
    primarykey
    data
    text
    <p>So I have a multimap, where the key is a struct, and the values are another struct.</p> <pre><code>multimap&lt;struct, struct&gt; multimap1; </code></pre> <p><code>multimap1</code> contains (format is <code>key</code>: <code>value</code>)</p> <pre><code>1: Random Value 1 2: Random Value 2 3: Random Value 3 4: Random Value 4 </code></pre> <p>I am trying to erase a value and a <em>key</em> from the multimap. Let's say I want to remove the second entry of the multimap. The result should be this:</p> <pre><code>1: Random Value 1 3: Random Value 3 4: Random Value 4 </code></pre> <p>I have an iterator that points the second <em>value</em>, so when I erase it using <code>multimap1.erase(it)</code>, it should remove the second entry (at least I think it should). I have been reading up on removing entries and from multimaps and it seems that only the value is removed from the multimap, not the key. So if erase the second entry with an iterator pointing to the second <em>value</em>, it would do this (Correct me if I am wrong):</p> <pre><code>1: Random Value 1 2: 3: Random Value 3 4: Random Value 4 </code></pre> <p>Is there a way to get the middle value result?</p> <p>Edit: So I am apparently wrong. If you do erase, you do get the middle result. I am trying to figure why I am not erasing correctly because, my code segfaults when I call the erase. If I call <code>it-&gt;first</code>, it returns the key of the element I want removed. If I call <code>it-&gt;second</code>, it returns the value of that key. So if I call <code>multimap.erase(it)</code>, It should remove the entire thing, correct?</p> <p>Edit 2: In my code, I printed out <code>it-&gt;first</code> and <code>it-&gt;second</code> to make sure that the pointer was pointing to the correct element and it was. When I called <code>multimap.erase(it)</code>, I stopped the loop and printed out the remaining elements in the multimap. It prints the first element correctly, but then the second element is printed something like this (output from compiler):</p> <pre><code>GEWolfC?`6??2?x3??2??2?x 1@4?????BUYA????BadWolfCorp1????AMstyKrq?4?X3??(4??3? X3PlanetExpress1GEqp7?L???5?d?5?x5??5?d2q7?7?X3??(4??3?X3?? </code></pre> <p>So obviously, it is not deleting correctly. I am running g++ 4.7 on linux. </p> <p>Edit 3: Sorry for so many edits, I want to keep the original question so people can reference it in the future. Just to experiment, I called <code>multimap.erase(it-&gt;first)</code> and that worked correctly. Can someone explain to me why this worked and what is going on here?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload