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()

  • 相关阅读:
    POJ2524+并查集
    POJ3697+BFS+hash存边
    POJ1151+线段树+扫描线
    POJ2528+线段树
    ubuntu 和 win7 远程登陆 + vnc登陆
    POJ3690+位运算
    POJ3283+字典树
    POJ3282+模拟
    POJ2349+prim
    2016.6.13
  • 原文地址:https://www.cnblogs.com/dyc0113/p/3202166.html
Copyright © 2011-2022 走看看