#include <iostream.h>
class number
{
char *ch;
int l;
public:
number()
{char c;
cin>>c;
ch= new char(c);
cout<<"please input a number:";
for(int i=1;cin>>c;i++)
{ ch++;
ch= new char(c);
l=i+1;
}
}
~number()
{cout<<ch[0]<<endl;
delete[] ch;}
friend number &operator+(number &a,number &b);
friend number mod(number d);
};
number mod(number d)
{
if(d.ch[0]=='-') d.ch[0]='+';
return d;
}
number operator+(number &a,number &b)
{
int j=0,m;
number temp;
if(a.l<b.l) {temp=a;a=b;b=temp;}
for(int i=m-1;i>0;i++)
{
int n,r,s;
n=a.ch[i]-'0'; r=b.ch[i]-'0'+j;
if(n+r>10){a.ch[i]=a.ch[i]+r+n-10; j=1;}
}
return a;
}
运行总是出错:
e:\c++\number\number.h(35) : error C2556: 'class number __cdecl operator +(class number &,class number &)' : overloaded function differs only by return type from 'class number &__cdecl operator +(class number &,class number &)'
e:\c++\number\number.h(21) : see declaration of '+'
e:\c++\number\number.h(35) : error C2040: '+' : 'class number (class number &,class number &)' differs in levels of indirection from 'class number &(class number &,class number &)'
Error executing cl.exe.
我检查不出什么错,请大家帮下忙,谢谢!!