ormanscuss 2022-05-27 23:23 采纳率: 100%
浏览 13
已结题

为什么这个拷贝构造函数执行了四次,两次传参是反过来的吗

为什么这个拷贝构造函数执行了四次,两次传参是反过来的吗

CAssembly::CAssembly(Part xone, Part xtwo)
: one(xone), two(xtwo), date(10)
{
cout << " good_2! Constructor of Class CAssembly called" << endl;
Part::Part() : val(0)
{
cout << " good_1! Default Constructor of Class Part called" << ", val = " << val << endl;
}

Part::Part(int i) : val(i)
{
cout << " good_2! Constructor1 of Class Part called" << ", val = " << val << endl;
}
Part::Part(Part& pt)
{
val = pt.val;
cout << " well! Copy Constructor of Class Part called" << ", val = " << val << endl;
Part:: ~Part()
{
cout << " over! Destructor of Class Part called" << endl;
}

Part one;                           //构造对象:配件1 ,val = 0Part two(10);         

CAssembly myAssC(one, two);
输出结果
well!Copy Constructor of Class Part called, val = 10
well!Copy Constructor of Class Part called, val = 0
well!Copy Constructor of Class Part called, val = 0
well!Copy Constructor of Class Part called, val = 10
good_2!Constructor of Class CAssembly called
over!Destructor of Class Part called
over!Destructor of Class Part called

  • 写回答

0条回答 默认 最新

    报告相同问题?

    问题事件

    • 系统已结题 6月4日
    • 创建了问题 5月27日

    悬赏问题

    • ¥15 pcl运行在qt msvc2019环境运行效率低于visual studio 2019
    • ¥15 MAUI,Zxing扫码,华为手机没反应。可提高悬赏
    • ¥15 python运行报错 ModuleNotFoundError: No module named 'torch'
    • ¥100 华为手机私有App后台保活
    • ¥15 sqlserver中加密的密码字段查询问题
    • ¥20 有谁能看看我coe文件到底哪儿有问题吗?
    • ¥20 我的这个coe文件到底哪儿出问题了
    • ¥15 matlab使用自定义函数时一直报错输入参数过多
    • ¥15 设计一个温度闭环控制系统
    • ¥100 rtmpose姿态评估