永发信息网

C++析构和构造问题

答案:1  悬赏:30  手机版
解决时间 2021-06-03 14:15
  • 提问者网友:嘚啵嘚啵
  • 2021-06-02 21:38
#include<iostream.h>
class A{
private:
int xx;
public:
A(int n)
{
xx = n;
static int i = 0;
cout<<"\nA_int called"<<++i<<"times!xx="<<xx;
}
A(double y)
{
xx = int(y+0.5);
static int j = 0;
cout<<"\nA_double called "<<++j<<"times!xx="<<xx;
}
A(A &a)
{
xx = a.xx;
static int k = 0;
cout<<"\nA_copy called"<<++k<<"times! xx="<<xx;
}
~A()
{
static int m = 0;
cout<<"\n~A() called"<<++m<<" times! xx = "<<xx;
}
};
A &Func(A &);
int main()
{
cout<<"\n Enter main":
A z(11);
A z1 = A(11.5);
z = 14;
z1 = A(17.3);
A z2 = z;
cout<<"\n Start Func...";
Func(z);
cout<<"\n Exit main";
return 0;
}
A &Func(A &a)
{
cout<<"\n In Func...";
return a;
}
最佳答案
  • 五星知识达人网友:空山清雨
  • 2021-06-02 21:56

int main()
{
cout<<"\n Enter main":
A z(11);//调用A(int n),精确匹配
A z1 = A(11.5);//调用A(double y),精确匹配
z = 14;//调用A(int n)
z1 = A(17.3);//调用A(double y),精确匹配
A z2 = z;//A(A &a)
cout<<"\n Start Func...";
Func(z);
cout<<"\n Exit main";
return 0;
}


我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯