定义计数器counter,重载运算符+
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
class counter
{
private:
int i;
public:
counter(){}
counter(int p){i=p;}
~counter(){}
int geti()
{
return i;
}
void seti(int p)
{
i=p;
}
counter operator+(counter &r)
{
return counter(i+r.geti());
}
};
int main()
{
counter a(1),b(2),c;
c=a+b;
cout<<c.geti()<<endl;
}