Why is the destructor called when initializing a vector of objects?
<p>Something occurred in my program, and I can't find if it's supposed to happen or not. And if it is, I don't see why..</p>

<p>Here's the code :</p>

<pre><code>#include &lt;iostream&gt;
#include &lt;vector&gt;

using namespace std;

class A{
  public:
    A();
    ~A();
};

A::A(){
  cout &lt;&lt; "creating" &lt;&lt; endl;
}

A::~A(){
  cout &lt;&lt; "deleting" &lt;&lt; endl;
}

int main(void){
  vector&lt;vector&lt;A &gt; &gt; vec;

  vec.resize(5);
  for(int i = 0; i &lt; 5; ++i){
    vec[i].resize(5);
  }

  cout &lt;&lt; "END" &lt;&lt; endl;

  return 0;
}
</code></pre>

<p>And here's the output :</p>

<pre><code>creating
deleting
creating
deleting
creating
deleting
creating
deleting
creating
deleting
END
deleting
deleting
[..more deleting here]
</code></pre>

<p>I understand why the destructor is called after the "END" message, but before, I don't. I thought that when the vector resize, the constructor of the class is called, but why the destructor?</p>
