Well, I'm testing the operator + function for my biginteger class, and so I wrote myself a little function to add by integer and one to add by biginteger.
1 2
|
biginteger operator + ( intmax_t n ) const { ... }
biginteger operator + ( const biginteger& that ) const { ... }
| |
Of course, my test case looks like this:
But the compiler starts spewing errors because it can't figure out which operator to use. Next I add a whole bunch of overloads for
int,
unsigned,
long, and
unsigned long,
short, etc, thinking that it needed an exact match.
Nope.
So I get rid of
everything except
operator + ( const biginteger& ) const
, since the constructor takes all kinds of stuff (so that bigintegers can be automatically constructed from a variety of integers and strings).
Still doesn't work.
So after googling around a bit I try moving definitions outside the class, using non-reference arguments, etc. (I figured this was bunk, but it was worth trying.)
Eventually I just commented out
all arithmetic operators. Surprisingly, it
still compiled. This confused me. The sum of 9999 and 9 was... 10.
After looking around, I found and commented out
operator bool () const
.
Lo and behold, it suddenly began working!
???
Since when does that make sense?
Stupid C++.
On an unrelated note, or related, I'm not sure, here's some fun I found while googling:
http://www.steike.com/code/useless/evil-c/
I like the "goes toward" operator.