Copy constuctor called many times when data is inserted in vector
<pre><code>#include &lt;iostream&gt;
#include &lt;vector&gt;
using namespace std;
class base
{
    int x;
public:
    base(int k){x =k; }
    void display()
    {
        cout&lt;&lt;x&lt;&lt;endl;
    }

    base(const base&amp;)
    {
        cout&lt;&lt;"base copy constructor:"&lt;&lt;endl;
    }
};
int main()
{
    vector&lt;base&gt; v;
    base obase[5]={4,14,19,24,29};
    for(int i=0; i&lt;5; i++)
    {
        v.push_back(obase[i]);
    }

}
</code></pre>

<p>When data is inserted into vector, copy to that data goes to vector using the copy constructor.</p>

<p>When i run this  program, </p>

<ol>
<li>for the first insertion  (i=0), one time copy constructor is called.</li>
<li>for the second insertion  (i=1), two times copy constructor is called</li>
<li>for the third insertion  (i=3), three times copy constructor is called</li>
<li>for the fourth insertion  (i=3), four times copy constructor is called</li>
<li>for the fifth insertion  (i=4), five times copy constructor is called</li>
</ol>

<p>Please any one can tell me why this is happening? For each insertion, shouldn't the copy constructor be called only once?</p>
