问题描述,编写Integer类使下列代码输出为1
int i=2;int j=7;
Integer x(i);Integer y(j);
cout<<(x+y==j-i)<<endl;
解决办法:
#include<cstdio>
#include<iostream>
using namespace std;
class Integer
{
int n;
public :Integer(int i)
{
n=i;
}
int operator+(Integer b)
{
return -(this->n)+b.n;
}
} ;
int main()
{
int i=2;int j=7;
Integer x(i);Integer y(j);
cout<<(x+y==j-i)<<endl;
}