请问为何此程序会出现两次析构函数调用~谢谢大家!
#include<iostream>#include<string>
using namespace std;
class Student
{
public:
Student::Student(string a,int b,float c);
Student();
~Student();
void show();
private:
string name;
int num;
float grade;
};
Student::Student()
{
cout<<num<<"_默认构造函数"<<endl;
}
Student::~Student()
{
cout<<num<<"_析构函数"<<endl;
}
void Student::show()
{
cout<<"学生信息为:"<<endl;
cout<<name<<"_"<<num<<"_"<<grade<<endl;
}
Student::Student(string a,int b,float c):name(a),num(b),grade(c){ cout<<num<<"_带参数的构造函数!"<<endl; };
int main()
{
// Student stu[3]={Student("Amos",1022,98.5),Student("Vivien",1021,95.5),Student("Leon",1023,91.5)};
// stu[0].show();
// stu[1].show();
// stu[2].show();
Student A =Student("Amos",1022,98.5);
Student B =Student("Vivien",1021,95.5);
Student C =Student("Leon",1023,91.5);
A.show();
B.show();
C.show();
}