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 }


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM