C++ Deep Copying a pointer to a map with pointer values
<p>I am having a bit of trouble deep copying a pointer to a map of pointer values.</p>

<pre><code>std::map&lt;string, TH1D*&gt;* m_hist_split;
</code></pre>

<p>My current method:</p>

<p>I am using a class template that copies the map pair and initializes the value of the pair on the heap. the template then returns a map::type_value</p>

<pre><code>#ifndef DEEPCOPY_H
#define DEEPCOPY_H

#include &lt;map&gt;
#include &lt;algorithm&gt;

namespace DeepCopy{

  template&lt;class A, class B&gt;
    struct MapPointerValue{
      typedef typename std::map&lt; A, B* &gt;::value_type map_t;
      map_t operator() (map_t p){
        return std::make_pair(p.first, new B(*p.second) );
      }
    };

...
...

}
#endif
</code></pre>

<p>Inside my copy constructor I then <strong>attempt</strong> to deep copy my pointer to a map of pointer values.</p>

<pre><code>Cutflow::Cutflow(const Cutflow&amp; cpy){

m_hist_split = new map&lt;string, TH1D*&gt;;
transform(cpy.m_hist_split-&gt;begin(),cpy.m_hist_split-&gt;end(), inserter(m_hist_split, m_hist_split-&gt;begin()), DeepCopy::MapPointerValue&lt;string, TH1D&gt;() );

...
...

}
</code></pre>

<p>When compiling I then get an ugly error :-( :</p>

<pre><code>Compiling src/Cutflow.cxx to obj/Cutflow.o
x86_64-slc5-gcc34-opt/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.3.2/../../../../include/c++/4.3.2/bits/stl_iterator.h: In instantiation of 'std::insert_iterator&lt;std::map&lt;std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;, TH1D*, std::less&lt;std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt;, std::allocator&lt;std::pair&lt;const std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;, TH1D*&gt; &gt; &gt;*&gt;':
src/Cutflow.cxx:42:   instantiated from here
x86_64-slc5-gcc34-opt/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.3.2/../../../../include/c++/4.3.2/bits/stl_iterator.h:562: error: 'std::map&lt;std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;, TH1D*, std::less&lt;std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt;, std::allocator&lt;std::pair&lt;const std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;, TH1D*&gt; &gt; &gt;*' is not a class, struct, or union type
x86_64-slc5-gcc34-opt/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.3.2/../../../../include/c++/4.3.2/bits/stl_iterator.h:572: error: 'std::map&lt;std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;, TH1D*, std::less&lt;std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt;, std::allocator&lt;std::pair&lt;const std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;, TH1D*&gt; &gt; &gt;*' is not a class, struct, or union type
x86_64-slc5-gcc34-opt/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.3.2/../../../../include/c++/4.3.2/bits/stl_iterator.h:599: error: 'std::map&lt;std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;, TH1D*, std::less&lt;std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt;, std::allocator&lt;std::pair&lt;const std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;, TH1D*&gt; &gt; &gt;*' is not a class, struct, or union type
x86_64-slc5-gcc34-opt/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.3.2/../../../../include/c++/4.3.2/bits/stl_iterator.h:608: error: 'std::map&lt;std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;, TH1D*, std::less&lt;std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt;, std::allocator&lt;std::pair&lt;const std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;, TH1D*&gt; &gt; &gt;*' is not a class, struct, or union type
x86_64-slc5-gcc34-opt/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.3.2/../../../../include/c++/4.3.2/bits/stl_iterator.h: In function 'std::insert_iterator&lt;_Container&gt; std::inserter(_Container&amp;, _Iterator) [with _Container = std::map&lt;std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;, TH1D*, std::less&lt;std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt;, std::allocator&lt;std::pair&lt;const std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;, TH1D*&gt; &gt; &gt;*, _Iterator = std::_Rb_tree_iterator&lt;std::pair&lt;const std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;, TH1D*&gt; &gt;]':
src/Cutflow.cxx:42:   instantiated from here
x86_64-slc5-gcc34-opt/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.3.2/../../../../include/c++/4.3.2/bits/stl_iterator.h:648: error: 'std::map&lt;std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;, TH1D*, std::less&lt;std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt;, std::allocator&lt;std::pair&lt;const std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;, TH1D*&gt; &gt; &gt;*' is not a class, struct, or union type
x86_64-slc5-gcc34-opt/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.3.2/../../../../include/c++/4.3.2/bits/stl_algo.h: In function '_OIter std::transform(_IIter, _IIter, _OIter, _UnaryOperation) [with _IIter = std::_Rb_tree_iterator&lt;std::pair&lt;const std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;, TH1D*&gt; &gt;, _OIter = std::insert_iterator&lt;std::map&lt;std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;, TH1D*, std::less&lt;std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt;, std::allocator&lt;std::pair&lt;const std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;, TH1D*&gt; &gt; &gt;*&gt;, _UnaryOperation = DeepCopy::MapPointerValue&lt;std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;, TH1D&gt;]':
src/Cutflow.cxx:42:   instantiated from here
x86_64-slc5-gcc34-opt/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.3.2/../../../../include/c++/4.3.2/bits/stl_algo.h:4281: error: no match for 'operator=' in '__result.std::insert_iterator&lt;_Container&gt;::operator* [with _Container = std::map&lt;std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;, TH1D*, std::less&lt;std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt;, std::allocator&lt;std::pair&lt;const std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;, TH1D*&gt; &gt; &gt;*]() = DeepCopy::MapPointerValue&lt;A, B&gt;::operator()(typename std::map&lt;A, B*, std::less&lt;_Key&gt;, std::allocator&lt;std::pair&lt;const A, B*&gt; &gt; &gt;::value_type) [with A = std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;, B = TH1D](std::pair&lt;const std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;, TH1D*&gt;(((const std::pair&lt;const std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;, TH1D*&gt;&amp;)((const std::pair&lt;const std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;, TH1D*&gt;*)__first.std::_Rb_tree_iterator&lt;_Tp&gt;::operator* [with _Tp = std::pair&lt;const std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;, TH1D*&gt;]()))))'
x86_64-slc5-gcc34-opt/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.3.2/../../../../include/c++/4.3.2/bits/stl_iterator.h:559: note: candidates are: std::insert_iterator&lt;std::map&lt;std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;, TH1D*, std::less&lt;std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt;, std::allocator&lt;std::pair&lt;const std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;, TH1D*&gt; &gt; &gt;*&gt;&amp; std::insert_iterator&lt;std::map&lt;std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;, TH1D*, std::less&lt;std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt;, std::allocator&lt;std::pair&lt;const std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;, TH1D*&gt; &gt; &gt;*&gt;::operator=(const std::insert_iterator&lt;std::map&lt;std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;, TH1D*, std::less&lt;std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt;, std::allocator&lt;std::pair&lt;const std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;, TH1D*&gt; &gt; &gt;*&gt;&amp;)
</code></pre>

<p>Any ideas what I am doing wrong.</p>

<p>Also,</p>

<p>is what I am doing correct?</p>

<p>:-D</p>
