How would I overload the '=' operator so that I can have
ooint = int;
Would the following work?
Code:ooint operator = ( const ooint & lhs ) { int hold = lhs.converttoint(); char s[10]; sprintf ( s, "%d", hold ); return ooint ( s ); }
How would I overload the '=' operator so that I can have
ooint = int;
Would the following work?
Code:ooint operator = ( const ooint & lhs ) { int hold = lhs.converttoint(); char s[10]; sprintf ( s, "%d", hold ); return ooint ( s ); }
>Would the following work?
No, because you'er passing an object of ooint, not an integer. Try taking an int, converting it to a C string, and calling operator= that takes a C string:
-PreludeCode:const ooint & ooint::operator = ( int rhs ) { char s[10]; sprintf ( s, "%d", rhs ); return operator= ( s ); }
My best code is written with the delete key.
I thought you had to have a member of the class type, though?
Thanks so much, I'll try that when I get home.
>I thought you had to have a member of the class type, though?
Only if the overloaded operator is global. If the operator is a member function then the left hand side is automatically *this.
-Prelude
My best code is written with the delete key.
I'm in your debt, Prelude. Thank you so much! I'll post the class when I'm done.
Besides weird manipulations, it will let you bypass the atoi and itoas. I think that that would be very convenient because I hate that.
const ooint & operator += ( const ooint & str ); // append str
const ooint & operator += ( const char * s); // append s
const ooint & operator += ( char ch ); // append char
Those append (they're from the original header), and I want them to act as if they were integers. Problem is, I'm not quite sure how to go about doing this.
I need 5 possibilities: as above, only not appending (i.e.: a+=1 means a = a + 1 not strcat(a,"1"))
const ooint & operator += ( const ooint & str );
const ooint & operator += ( const char * s);
const ooint & operator += ( char ch );
const ooint operator + ( const ooint & lhs, int rhs );
const ooint operator + ( const ooint & lhs, const ooint & rhs )
Something like that, but I still don't have it figured out.
Operator/Operation Performed
*= Multiplication assignment
/= Division assignment
%= Remainder assignment
+= Addition assignment
-= Subtraction assignment
&= Bitwise-AND assignment
|= Bitwise-inclusive-OR assignment
^= Bitwise-exclusive-OR assignment
I need all of those with 5 each (all possible combinations), and I have no clue