??????错在那里啊
不知道是编译器的问题还是程序有问题 我用的是VC++6.0的编译器 请高手指路#include<iostream>
using namespace std;
//-------------------------------------------
class Integer
{
public:
void set(int ii=0){i=ii;}
Interger operator+(int);
Interger operator+(Interger&);
private:
int i;
};
//-------------------------------------------
Integer Integer::operator+(int x)
{
Integer result;
result.set(i+x);
return result;
}
//-------------------------------------------
Integer Integer::operator+(Integer& x)
{
Integer result;
result.set(i+x.i);
return result;
}
//-------------------------------------------
class Integer2
{
public:
void set(int ii=0){i=ii;}
friend Integer2 operator+(Integer2&,Integer2&);
friend Integer2 operator+(Integer2&,int);
friend Integer2 operator+(int,Integer2&);
private:
int i;
};
//--------------------------------------------
Integer2 operator+(Integer2& x,Integer2& y)
{
Integer2 result;
result.set(x.i+y.i);
result result;
}
//--------------------------------------------
Integer2 operator+(Integer2& x,int a)
{
Integer2 result;
result.set(x.i+a);
return result;
}
//--------------------------------------------
Integer2 operator+(int a,Integer2& x)
{
Integer2 result;
result.set(a+x.i);
return result;
}
//--------------------------------------------
int main()
{
Integer A,B,C;
A.set(20);
C.set(10);
B=A+4;
B=A+C;
Integer2 D,E,F;
D.set(100);
F.set(200);
E=D+40;
E=D+F;
E=40+D;
return 0;
}
//--------------------------------------------