执行到析构函数怎么出错了?
#include<iostream>
#include<string>
using namespace std;
class Student
{
public:
Student()
{
m_strName1=new char[20];
}
Student(string _name,int _age)
{
m_strName2=_name;
m_intAge2=_age;
}
~Student()
{
cout<<"已运行析构函数"<<endl;
delete []m_strName1;
m_strName1=NULL;
}
Student(const Student &kelong):m_strName3("duoli"),m_intAge3(1)
{
cout<<"已运行拷贝构造函数"<<endl;
}
void setName()
{
cin>>m_strName1;
}
void getInformation1()
{
cout<<m_strName1<<endl;
}
void getInformation2()
{
cout<<m_strName2<<m_intAge2<<endl;
}
void getInformation3()
{
cout<<m_strName3<<m_intAge3<<endl;
}
private:
char *m_strName1;
string m_strName2;
string m_strName3;
int m_intAge2;
int m_intAge3;
};
int main()
{
Student t1;
Student t2("baoyanghao",19);
Student t3(t1);
t1.setName();
t1.getInformation1();
t2.getInformation2();
t3.getInformation3();
return 0;
}
析构函数只能执行一次,理应是三次 而且这一次还出错了 