Access violation error on inserting data to map variable
<p>I have declared a map variable in header file and trying to insert some values to this from a method in cpp file.</p>

<p>In header (<code>.h</code>) file,</p>

<pre><code>class Test
{
public:
    void AddName(const std::string&amp; name, const std::string&amp; value);
private:
    std::map&lt;std::string, std::string&gt; m_names;
};
</code></pre>

<p>In <code>.cpp</code> file,</p>

<pre><code>void Test::AddName(const std::string&amp; name, const std::string&amp; value)
{
    m_names.insert(std::pair&lt;std::string, std::string&gt;(name, value));
}
</code></pre>

<blockquote>
  <p>This method throws the error: "0xC0000005: Access violation reading
  location 0x0000000000000150."</p>
</blockquote>

<p>But if I declare this map variable with in this <code>AddName method</code>, then no error.</p>

<p>I am calling this AddName method from another class with required parameters.</p>

<pre><code>TestPtr test = nullptr;
test-&gt;AddName(nodeDetails.Attribute("Name"), nodeDetails.Attribute("Value"));
</code></pre>

<p>What is the issue?</p>