I have the following code:
#include <iostream>
#include <vector>
using std::cout;
using std::endl;
using std::vector;
class A {
public:
int i;
A(int i=0):i(i) {
cout << "A::A() called" << endl;
}
~A() {
cout << "A::~A() called" << endl;
}
};
int main() {
vector<A> *a = new vector<A>(3);
delete a;
}
The program prints:
A::A() called
A::~A() called
A::~A() called
A::~A() called
A::~A() called
Why do I see one constructor and four destructors called ?
I am using g++ 4.8.4.