Basic question in assigning value to unordered_map
<p>I have an unordered_map which stores the int as key an pointer as value. I need to check the existence of the key. If the key is not available, I need to insert the key and value. Which one is the better approach?</p>

<p>Thanks.</p>

<pre><code>unordered_map&lt;int, classA*&gt;testMap;
classA* ptr = testMap[1];
if(ptr == NULL)
   testMap[1] = new classA;


OR

unordered_map&lt;int, classA*&gt;::iterator it = testMap.find(1);
if(it == testMap.end())
{
  testMap.insert(make_pair(1, new classA));
}
</code></pre>
