深复制

来源:互联网 发布:淘宝那些解id锁靠谱吗 编辑:程序博客网 时间:2024/05/01 14:22

  1. /*
     *copyright(c) 2014,烟台大学计算机学院
     *All rights reserved
     *文件名称:test.cpp
     *作者:吴雨凡
     *版本:v6.0
     *
     *问题描述:深复制

     *输入描述:
     *程序输出:判断相关问题
    */

  2. #include<cstring>  
  3. using namespace std;  
  4. class A  
  5. {  
  6. private:  
  7.     char *a;  
  8. public:  
  9.     A(char *aa)  
  10.     {  
  11.         a = new char[strlen(aa)+1];  
  12.         strcpy(a,aa);  
  13.     }  
  14.     A(A &b)  
  15.     {  
  16.         a = new char[strlen(b.a)+1];  
  17.         strcpy(a,b.a);  
  18.     }  
  19.     ~A()  
  20.     {  
  21.         delete []a;  
  22.     }  
  23.     void output()  
  24.     {  
  25.         cout<<a<<endl;  
  26.     }  
  27. };  
  28. int main(){  
  29.     A a("good morning, code monkeys!");  
  30.     a.output();  
  31.     A b(a);  
  32.     b.output();  
  33.     return 0;  
  34. }  
0 0
原创粉丝点击