析构函数没有调用
来源:百度知道 编辑:UC知道 时间:2024/07/02 10:46:20
我用Dev-C++编译器,为什么析构函数没有被调用呢。没有任何错误。除了析构函数外,其他一切正常。
#include<iostream>
using namespace std;
class a
{
public:
a()
{
cout<<"构造函数"<<endl;
}
~a()
{
cout<<"析构函数"<<endl;
}
};
int main()
{
a *p;
p=new a;
system("pause");
delete p;
system("pause");
return 0;
}
这样是可以调用的
#include<iostream>
using namespace std;
class a
{
public:
a()
{
cout<<"构造函数"<<endl;
}
~a()
{
cout<<"析构函数"<<endl;
}
};
int main()
{
a b;
system("pause");
return 0;
}
这样在Dev-C++ 中调用不了析构函数
第二个 我在 vc60 中试过了 可以调用 析构函数的
不太明白你的意思,析构函数是自动调用的,不能重载,一般情况下遇到花括号时会自动调用
请写出程序以及程序输出信息。