一直不太明白c++对象销毁的过程,
代码
#include <iostream>
using namespace std;
class X
{
?public:
??X(){
??? cout << "X()" << endl;????
???? }
??~X(){
??? cout << "~X()" << endl;
??}
??void show(){
???cout << "show()" << endl;
??}
};
int main(){
?
?X *x = 0;
?cout << x << endl;
?{
??? X *xx = new X();
??? x = xx;
??? cout << xx << endl;
?}
?? delete x;
?? x->show();
?? cout << x << endl;
}
?
结果
0
X()
0x3e4d20
~X()
show()
0x3e4d20
可是?? x->show();还是可以的,那么对象被销毁了吗,还是只是调用了一次析构函数而已。
?