1 #include "stdafx.h"
 2 #include <iostream>
 3 #include <string>
 4 using namespace std;
 5 
 6 class Test
 7 {
 8 public:
 9     Test():mValue(2),mName("karen")
10     {
11     }
12     Test(string x,int y)
13     {
14       mName = x;
15       mValue = y;
16     }
17     ~Test()
18     {
19     }
20     int getValue()
21     {
22      return mValue;
23     }
24     string getName()
25     {
26      return mName;
27     }
28     Test& operator=(Test& t);
29 private:
30     int mValue;
31     std::string mName;
32 };
33 /*赋值操作*/
34 Test& Test::operator = (Test& t)
35 {
36     mName = t.mName;
37     mValue = t.mValue;
38     return *this;
39 }
40 
41 int _tmain(int argc, _TCHAR* argv[])
42 {
43     /*赋值操作*/
44     Test t1("karen",3);
45     Test t2("huge",5);
46     Test t3;
47     t2 = t1;
48     cout<<t2.getName()<<t2.getValue()<<endl;
49     t3 = t1;
50     cout<<t3.getName()<<t3.getValue()<<endl;
51     return 0;
52 }

相关文章:

  • 2021-07-21
  • 2021-10-14
  • 2022-12-23
  • 2021-04-30
  • 2021-07-14
  • 2021-09-27
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-09-05
  • 2022-01-17
  • 2021-06-17
  • 2022-01-18
  • 2022-12-23
  • 2022-02-11
  • 2021-10-02
相关资源
相似解决方案