C++ 运算符重载

 1 #include <iostream>
 2 using namespace std;
 3 
 4 class Good
 5 {
 6 public:
 7     int member;
 8     Good(int a): member(a)
 9     {
10         cout << "调用构造" << endl;
11     }
12     void show()
13     {
14         cout << member << endl;
15     }
16     Good operator+(const Good& obj)
17     {
18         return Good(member - obj.member);
19     }
20 };
21 
22 int main(int argc, char *argv[])
23 {
24     Good a(10), b(20);
25     Good c = a + b;
26     c.show();
27     return 0;
28 }

 

posted @ 2014-03-25 21:13  秋月的私语  阅读(200)  评论(0编辑  收藏  举报