Failed to shallow copy an object
<p>I have a class</p>

<pre><code>template&lt;typename T&gt; class RGBHistogramTrait
{
public:
    RGBHistogramTrait(const QImage &amp;image, RGBHistogram&lt;T&gt; hist) : _hist(hist), _base((QRgb *) (image.bits()));
private:
    const QRgb *_base;
    RGBHistogram&lt;T&gt; _hist;
};
</code></pre>

<p>and</p>

<pre><code>template&lt;typename T&gt; struct RGBHistogram
{
    RGBHistogram&lt;T&gt;(Histogram&lt;T&gt; &amp;redHist, Histogram&lt;T&gt; &amp;greenHist, Histogram&lt;T&gt; &amp;blueHist)
        : redHist(redHist), greenHist(greenHist), blueHist(blueHist) {}

    Histogram&lt;T&gt; &amp;redHist, &amp;greenHist, &amp;blueHist;
};
</code></pre>

<p>Now i have a single object RGBHistogram. I want to create like 100 instances of RGBHistogramTrait, each instance of RGBHistogramTrait should create a copy of RGBHistogram, each instance will be used by a thread. </p>

<p>I will aggregate the results from the 100 threads back into the original RGBHistogram. The problem is that somehow _hist in each instance of RGBHistogramTrait is pointing to the same thing (the original RGBHistogram). I thought I already shallow copied RGBHistogram in RGBHistogramTrait's constructor by  _hist(hist). RGBHistogram has a std::map and no defined copy consturctor.</p>

<pre><code>template&lt;typename T&gt; void ImageReader&lt;T&gt;::calculate(RGBHistogram&lt;T&gt; &amp;hist)
{
    QImage image;

    if (image.load(QString::fromUtf8(_file.c_str())))
    {
        std::vector&lt;RGBHistogramTrait&lt;T&gt; &gt; *fs = new std::vector&lt;RGBHistogramTrait&lt;T&gt; &gt;[_threads];

        for (ThreadNum i = 0; i &lt; _threads; i++)
        {
            fs-&gt;push_back(RGBHistogramTrait&lt;T&gt;(image, hist));
        }

        ThreadCoord::start(image.width() * image.height(), _threads, *fs);

        // Now aggregate the results in fs back into the original hist    


        }
</code></pre>
