From: "Miguel Ángel R." Newsgroups: comp.os.msdos.djgpp Subject: Overloading operands with doubles Date: Mon, 13 Mar 2000 14:38:16 +0100 Organization: Telefonica Transmision de Datos Lines: 45 Message-ID: <8aiqko$br6$1@talia.mad.ttd.net> NNTP-Posting-Host: 195.57.122.109 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.00.2919.6600 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2919.6600 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com /* Hello All! I'm having troubles with this very simple class when I try to overload the + operand. It runs with shorts expresions: (i.e: a+b+a+b+a+b) but returns NaN ("Not a Number" numeric comprocesor exception, (DJGPP FAQ section 11.5)) or hungs... I supouse that the class is well definied because runs with instead of :-? (My computer is a Pentium MMX) Can anyone help me? Thank's for your time! ---------------------------------------------------------------------------- -- */ #include class Euro{ private: double eurocents; public: Euro(void) {eurocents=0;} Euro(double const euros) {eurocents=(euros * 100);} double Euros(void) {return(eurocents / 100);} Euro operator+ (const Euro &op) {return(Euro((eurocents + op.eurocents) / 100));} }; int main (){ Euro a(1),b(1),sum; sum=a+b; // sum=a+b+a+b+a+b+a+b+a+b+a+b+a+b+a+b+a+b+a+b+a+b+a+b+a+b+a+b; // It compiles but :'( printf("\nSum: %f",sum.Euros()); }