这是代码:
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main()
{
int *p = new int[2];
p[0] = 1;
p[1] = 2;
cout << *p++ << endl;
delete p;
return 0;
}
它可以编译,但出现运行时错误“free(): invalid pointer”,然后是内存映射。
操作系统 ubuntu 10.10
编译器:g++ 4.4.3