这段代码运行后会跳出“程序已停止工作”的提示框
#include<bits/stdc++.h>
using namespace std;
class A{
public:
int* xxx;
A(int l){
int* xxx=new int;
*xxx=5;
}
~A(){
delete xxx;
}
};
class B{
public:
A* head;
B(int c,int r){
head=(A*)operator new(c*sizeof(A));
for(int i=0;i<c;i++){
new(head+i) A(r);
printf("%d:%d\n",i,*(head[i].xxx));
}
}
~B(){
delete[] head;
}
};
int main(){
B b(3,3);
return 0;
}