#include <iostream>
#include <string>
using namespace std;
class N
{
public:
N()
{
cout<<"N()"<<endl;
}
~N()
{
cout<<"~N()"<<endl;
}
void set_name()
{
name = "Jim";
}
string get_name()
{
return name;
}
protected:
string name;
};
class B:public N
{
public:
B()
{
cout<<"B()"<<endl;
}
~B()
{
cout<<"~B()"<<endl;
}
};
class C:public B
{
public:
C()
{
cout<<"C()"<<endl;
}
~C()
{
cout<<"~C()"<<endl;
}
};
void text(C *n)
{
n->set_name();
delete n;
n = NULL;
}
int main ()
{
C c;
text(&c);
return 0;
}
看看这个代码
为什么运行时,调用了两次析构函数?而且视频中老师是说并不创建临时变量的呀
onemoo
相关分类