关于调用构造函数和析构函数的时机,求教!
程序没有错误,我主要不解的是关于构造函数和析构函数的调用时机问题不太清楚:
(我在构造函数和析构函数中都附加了一个输出)
我采用以下形式建立类:
#include<iostream.h>#include"EMPLOYEE.H"Employee test0("Esion0","You0");void main(){ cout<<"实例化前的对像个数是:"<<Employee::getCount()<<endl; Employee test1("Ivan","Long"); Employee test2("Esion","You"); cout<<"实例化后的对像个数是:"<<Employee::getCount()<<endl; { Employee test3("Esion2","You2"); } cout<<"实例化后的对像个数是:"<<Employee::getCount()<<endl; }#include<iostream.h>#include"EMPLOYEE.H"Employee *test0=new Employee("Esion0","You0");void main(){ cout<<"实例化前的对像个数是:"<<Employee::getCount()<<endl; Employee *test1=new Employee("Ivan","Long"); Employee *test2=new Employee("Esion","You"); cout<<"实例化后的对像个数是:"<<Employee::getCount()<<endl; { Employee *test3=new Employee("Esion2","You2"); } cout<<"实例化后的对像个数是:"<<Employee::getCount()<<endl; }