• 加了拷贝构造的 深更半夜最后一更


     1#include<iostream>
     2 using namespace std;
     3 class test{
     4 int mvalue;
     5 public:
     6         test(int i){
     7                 cout << "test(int i)=" << i << endl;
     8                 mvalue = i;
     9         }
    10         test(const test& obj){
    11                 cout << "const test& obj" << endl;
    12                 this->mvalue = obj.mvalue;
    13         }
    14         int value(){
    15                 return mvalue;
    16         }
    17         test& operator++(){
    18                 ++mvalue;
    19                 return *this;
    20         }
    21         //后++
    22         test operator++(int){
    23                 cout << "test operator++" << endl;
    24                 test ret(mvalue);
    25                 mvalue++;
    26                 cout << "mvalue=" << mvalue << endl;
    27                 return ret;
    28         }
    29 };
    30 int main(){
    31         test t(0);         //test(int i)=0
    32         test tt = t++;     //test operator ++; test(int i)=0
    33 
    34         cout << tt.value() << endl;
    35         cout << t.value() << endl;
    36         return 0;
    37 }
    38 //结果
    39 test(int i)=0
    40 test operator++
    41 test(int i)=0
    42 mvalue=1
    43 0
    44 1
  • 相关阅读:
    AGC007题解
    博弈论学习笔记
    ZROI2019 提高十连测
    男人八题2019
    LOJ 2840「JOISC 2018 Day 4」糖
    CF671D Roads in Yusland
    网络流套路小结
    BZOJ 3729 GTY的游戏
    AGC036C GP 2
    BZOJ 5046 分糖果游戏
  • 原文地址:https://www.cnblogs.com/DXGG-Bond/p/11886387.html
Copyright © 2020-2023  润新知