C++课程设计类作业3

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 class A
 4 {
 5 public:
 6     A()
 7     {
 8         a=b=0;
 9         cout<<"Default Constructor called.\n";
10     }
11     A(int i,int j)
12     {
13         a=i;
14         b=j;
15         cout<<"Constructor called.\n";
16     }
17     ~A()
18     {
19         cout<<"Destructor callled.\n";
20     }
21     void copy(A &aa);
22     void print()
23     {
24         cout<<a<<","<<b<<endl;
25     }
26 private:
27     int a,b;
28 };
29 void A::copy(A &aa)
30 {
31     if(this==&aa)
32         return;
33     *this=aa;
34 }
35 int main()
36 {
37     A a1,a2(3,4);
38     a1.copy(a2);
39     a1.print();
40 }

posted @ 2017-06-13 22:46  Angel_Kitty  阅读(1429)  评论(0编辑  收藏  举报