#include<bits/stdc++.h>
using namespace std;
class Counter
{
public:
int cnt = 0;
Counter(){}
Counter(int a) : cnt(a){}
Counter operator +(const Counter &c) const
{
return Counter(cnt + c.cnt);
}
};
int main()
{
Counter a(230), b(3), c;
c = a + b;
cout << c.cnt;
return 0;
}
重载运算符的时候要注意是几元运算符,重载运算符一般都有返回值,例如++、-- 一般返回当前类的类型。