Do not ask me what I'm trying to do, this is just a quick test and its only purpose is to see if there is something wrong with placement new.
I've found an issue, or I just misunderstood something.
#include <vector>
using namespace std;
#define WORKS
int main(int argc, char** argv) {
vector<int>* pp = (vector<int>*)malloc(sizeof(vector<int>)*20);
#ifdef WORKS
for(int i = 0; i < 20; ++i)
new (pp+i) vector<int>;
#else
new (pp) vector<int>[20];
#endif
for(int i = 0; i < 20; ++i)
pp[i].~vector<int>();
}
when you remove the "#define WORKS" it will give you access violation, like
for(int i = 0; i < 20; ++i)
new (pp+i) vector<int>;
which works good, was different from
new (pp) vector<int>[20];
which is the cause of throwing exceptions at the destruction stage. What's going on here? I'm working on Windows XP and building with VC++ Express 2010.