我是oop的初学者,这是我的问题
int main(){
int *p = new int[3];
p[0] = 1;
p[1] = 2;
p[2] = 3;
int* q = p;
p++; //here!
delete p;
}
和
int main(){
int *p = new int[3];
p[0] = 1;
p[1] = 2;
p[2] = 3;
int* q = p + 1;
p++; //here!
delete p;
}
有错误:被释放的指针没有被分配,但是和
int main(){
int *p = new int[3];
p[0] = 1;
p[1] = 2;
p[2] = 3;
int* q = p + 1;
delete p;
}
看起来不错!我想删除这个数组中的一个元素。有人能告诉我这个错误的原因吗?