为什么第一题执行一个构造函数就执行一个析构函数
class student{public:
student(string name1,string stu_no1,float score1){
name=name1;
stu_no=stu_no1;
score=score1;
cout<<"2"<<endl;
}
~student(){cout<<"1"<<endl;}
private:
string name;
string stu_no;
float score;
};
int main()
{
student stu[3]={
student("黎明","187691",90),
student("丹妮","187692",87),
student("珍妮","187693",96)};
return 0;
}
*/
//第二题
class complex{
public:
complex(double r=0.0,double i=0.0)
{real=r;imag=i;
cout<<"2"<<endl;
}
~complex()
{cout<<"1"<<endl;
}
private:
double real;
double imag;
};
int main()
{complex com[3]={
complex(1.1,2.2),
complex(3.3,4.4),
complex(5.5,6.6)};
return 0;
}