这是本人所编写的一段程序,有两个错误,请高手指正!

来源:百度知道 编辑:UC知道 时间:2024/09/23 03:57:14
#include<iostream>
using namespace std;
class Human
{
public:
Human(){cout<<"构造函数执行中:...\n";i=999;}
~Human(){cout<<"构造函数执行中...\n";}
private:
int i;
};
int main()
{
Human *p=new Human;
delete p;
return 0;
}

复制你的代码运行了下
就语法检测没有错:
Cpp1.exe - 0 error(s), 0 warning(s)

运行效果也没问题
显示:
构造函数执行中
构造函数执行中

不过,我认为,这一行
~Human(){cout<<"构造函数执行中...\n";}
应该是析构函数
改为
~Human(){cout<<"析构函数执行中...\n";}

我感觉也没有错,不知道你用什么编译器编译的,编译器不同,可能会有差别,同意楼上的答案