struct A {
int i;
};
struct B {
A* p;
void B() {
p = new A;
}
~B() {
delete p;
}
};
void sayHello(B b) {
// 函数体没有给出
}
int main() {
B b;
sayHello(b);
return 0;
}
A. 程序正常运行
B. 程序编译错误
C. 程序崩溃
D. 程序死循环
答案是:C
程序崩溃,B析构函数执行两次,重复释放p。