填写下方空白处代码,通过重载运算符使得Counter类型可以以x为值参与整数加法运算
#include<bits/stdc++.h>
using namespace std;
class Counter
{
public:
Counter(int d){x=d;}
int getx() const{return x;}
private:
int x;
};
//------------------code here----------------------------
//-------------------------------------------------------------
int main()
{
int a,y;
cin>>a>>y;
Counter x(a);
cout<<x+y<<' '<<y+x;
}
样例输入输出
10 12
22 22
22 22
int operator+(const Counter &c1, const int b) {
int x = c1.getx();
x += b;
return x;
}
int operator+(const int b, const Counter &c1) {
int x = c1.getx();
x += b;
return x;
}