|
代码如下:
#include<iostream>
#include<string>
using namespace std;
class Person{
public:
char* pname;
Person(char *name)
{
int len = strlen(name);
pname = new char(len+1);
memset(pname,0,len+1);
strcpy(pname,name);
cout << pname <<endl;
}
~Person(){
if(!pname){
cout << "delete" <<endl;
}
}
};
int main(){
{
Person* pst = new Person("123231321231312123312");
delete pst;
}
system("pause");
return 0;
}
代码如上 成员pname 是我new出来的,为什么我delete pst之后执行析构函数
为什么这句代码不输出呢,这里的pname为什么为NULL了 (我的pname是new出来的哇)
if(!pname){
cout << "delete" <<endl;
} |
上一篇: 析构函数的简单小问题下一篇: 求助,38课运算符重载这里
|