J
jjleto
When I run this simple program:
#include <vector>
#include <iostream>
using namespace std;
class A {
public:
A() { cout << "[ctor]" << endl; }
~A() { cout << "[dtor]" << endl; }
};
int main()
{
vector<A> v(3);
return 0;
}
I've got the following result:
[ctor]
[dtor]
[dtor]
[dtor]
[dtor]
(gcc 3.3.4)
How to explain that ? Should not the constructor be called 3 times and
the destructor also ?
Thanks.
#include <vector>
#include <iostream>
using namespace std;
class A {
public:
A() { cout << "[ctor]" << endl; }
~A() { cout << "[dtor]" << endl; }
};
int main()
{
vector<A> v(3);
return 0;
}
I've got the following result:
[ctor]
[dtor]
[dtor]
[dtor]
[dtor]
(gcc 3.3.4)
How to explain that ? Should not the constructor be called 3 times and
the destructor also ?
Thanks.