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