chongchong
知名会员
- 注册
- 2003-11-04
- 消息
- 163
- 荣誉分数
- 0
- 声望点数
- 126
Source code :
#include <iostream>
#include <iomanip>
#include <fstream>
#include <vector>
using namespace std;
class CDummy {
public:
CDummy() {
cout << "CDummy construct" << endl;
//cout << "address = " << hex << static_cast<void*>(buf) << endl;
}
virtual ~CDummy() {
cout << "CDummy destructor" << endl;
}
private:
char buf[102410];
};
int main(void) {
vector<CDummy> storage;
for(int i=0; i<2; i++) {
CDummy dummy;
storage.push_back(dummy);
}
cout << "----------------------" << endl;
}
output from execution:
CDummy construct
CDummy destructor
CDummy construct
CDummy destructor
CDummy destructor <-----------????????
----------------------
CDummy destructor
CDummy destructor
Can any one explain that why I get a extra destructor call which marked as <---------?????
#include <iostream>
#include <iomanip>
#include <fstream>
#include <vector>
using namespace std;
class CDummy {
public:
CDummy() {
cout << "CDummy construct" << endl;
//cout << "address = " << hex << static_cast<void*>(buf) << endl;
}
virtual ~CDummy() {
cout << "CDummy destructor" << endl;
}
private:
char buf[102410];
};
int main(void) {
vector<CDummy> storage;
for(int i=0; i<2; i++) {
CDummy dummy;
storage.push_back(dummy);
}
cout << "----------------------" << endl;
}
output from execution:
CDummy construct
CDummy destructor
CDummy construct
CDummy destructor
CDummy destructor <-----------????????
----------------------
CDummy destructor
CDummy destructor
Can any one explain that why I get a extra destructor call which marked as <---------?????