C++中析构函数没有被执行?

gaoyuanfeng gaoyuanfeng 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
请大家看下这段代码:
#include<iostream>
using namespace std;

class Student
{
public:
Student()
{
cout<<"constructing student."<<endl;
semesHours=100;
gpa=3.5;
}
~Student()
{
cout<<"destructing student."<<endl;
}
protected:
int semesHours;
float gpa;
};

class Teacher
{
public:
Teacher()
{
cout<<"constructing teacher."<<endl;
}
~Teacher()
{
cout<<"destructing teacher."<<endl;
}
};

class TutorPair
{
public:
TutorPair()
{
cout<<"constructing tutorPair."<<endl;
noMeetings=0;
}
~TutorPair()
{
cout<<"destructing tutorpair."<<endl;
}
protected:
Student student;
Teacher teacher;
int noMeetings;
};

int main()
{
TutorPair tp;
cout<<"back in main."<<endl;
while(1);
return 0;
}
我在VS2005中运行的结果是:
constructing student.
constructing teacher.
constructing tutorPair.
back in main.
为什么析构函数没有被执行呢?
...全文

相关推荐

评论 19
收藏 已收藏
分享
返回顶部
gaoyuanfeng
C++ 语言 65,214 成员 250,514 内容