我有以下代碼:載體構造函數/析構函數調用
#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;
}
該程序打印:
A::A() called
A::~A() called
A::~A() called
A::~A() called
A::~A() called
爲什麼我看到一個構造函數和四個析構函數叫什麼名字?
我使用的是g ++ 4.8.4。
拷貝構造函數被調用 – Amadeus
即輸出[錯](http://coliru.stacked-crooked.com/a/4dcfb98936905392)爲你列出的上述片段 – WhiZTiM
@WhiZTiM這是不正確的:http://coliru.stacked-crooked.com/a/1ecb4852b136545d輸出預計C++ 03 – Amadeus