operator overloading... I'm stuck
I'm working on a class I call a "int class" that allows weird manipulation of an "integer" which is stored as a dynamically allocated character array. I want to overload all operators that are usable with an integer, so that
ooint i = 0;
works just as well as
ooint i = '0';
or
ooint i = "0";
In fact, I don't want it to take it as a character or string at all! I want to be able to do
i = i+6;
so that in the class, it has something like itoa((atoi(i))+6),dummybuffer,10); to make it act like an integer, only stored as a string so that my weird manipulations can work.
I tried overloading the + like this:
Code:
ooint operator + (const int & lhs, const int & rhs)
{
char dummybuffer[1024];
int iResult = lhs + rhs;
itoa(iResult,dummybuffer,10);
ooint result(dummybuffer); // copies lhs to result
return result; // returns a copy of result
}
And I get this:
c:\filepath\ooint.cpp(187) : error C2803: 'operator +' must have at least one formal parameter of class type
Any ideas as to how I could get this to work? I don't want to have to do this:
i = "1" + "6"
If I had const ooint, then it would have to take it as a string, wouldn't it?