C++中析构函数没有被执行?
请大家看下这段代码:
#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.
为什么析构函数没有被执行呢?