网上看到这样一段代码:
#include <iostream>
using namespace std;
struct Base
{
Base() {cout<<"Base"<<endl;}
virtual ~Base() {cout<<"~Base"<<endl;}
int i;
};
struct Der : public Base
{
Der() {cout<<"Der"<<endl;}
virtual ~Der() {cout<<"~Der"<<endl;}
int it[10];
};
int main()
{
Base *bp = new Der;
Base *bq = new Der[5];
delete bp;
delete[] bq;
}
运行到delete[] bq时会产生EXC_BAD_ACCESS信号而core掉。
转载于:https://blog.51cto.com/loongcheng/1219447