zoukankan      html  css  js  c++  java
  • 在返回拷贝的函数当中,类的各种函数的调用,尤其以拷贝形式返回时调用比较复杂,一下是结果

    #include<iostream>
    #include<iomanip>
    #include<list>
    #include<cmath>
    #include<vector>
    using namespace std;
    
    struct Exmpl
    {
        Exmpl()
        {
            std::cout<<"Exmpl()"<<endl;
        }
        Exmpl(const Exmpl &)
        {
            cout<<"Exmpl( const Exmpl&)"<<endl;
        }
        Exmpl& operator=(const Exmpl &rhe)
        {
            cout<<"operator=(const Exmpl&)"<<endl;
            return *this;
        }
        ~Exmpl()
        {
            cout<<"~Exmpl()"<<endl;
        }
    };
    Exmpl func3()
    {
        Exmpl obj;  // 先构造一个对象,然后把这个对象复制到一个临时对象,接着析构这个对象,然后调用赋值操作符,然后析构临时对象...
        return obj;
    }
    
    void main()
    {
        
        Exmpl eobj;
        eobj=func3();
        system("pause");
    }

    函数运行结果

    Exmpl()

    Exmpl()

    Exmpl(const Exmpl&)

    ~Exmpl()

    operator=(const Exmpl&)

    ~Exmpl()

    ~Exmpl()

  • 相关阅读:
    前缀和
    hdu6290奢侈的旅行
    make_pair
    New Year and Buggy Bot
    STL next_permutation 算法原理和自行实现
    前端面试题集合
    node设置cookie
    黑客与geek
    xss
    node async
  • 原文地址:https://www.cnblogs.com/dyc0113/p/3202166.html
Copyright © 2011-2022 走看看