From: "Traveler" Newsgroups: comp.lang.c++,comp.os.msdos.djgpp Subject: Re: Points of view about Java... Date: Sun, 18 Mar 2001 13:38:24 +0200 Organization: SAUNALAHDEN asiakas Lines: 50 Message-ID: <9925d7$2m4$2@tron.sci.fi> References: <990mc1$aqg$1 AT tron DOT sci DOT fi> NNTP-Posting-Host: mkdcxlvii.hdyn.saunalahti.fi X-Trace: tron.sci.fi 984914151 2756 195.197.167.147 (18 Mar 2001 11:15:51 GMT) X-Complaints-To: newsmaster AT saunalahti DOT fi NNTP-Posting-Date: 18 Mar 2001 11:15:51 GMT X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4133.2400 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com > // Overloaded operator that calculates the x raised to y power. > // Use recursion or loop... > Number operator^(double exp) > { > // Your code comes here... > } > > ... since here you re-define the meaning of '^'. It's just one reason for > people to complain about operator overloading. Yeah, your right that operator overloading CAN be confusing if taken too far but thatīs why I am offering only the bare minimum for class so that people can deside if to use it or write their own "pow(double exp)" and the like functions.... I offer ALTERNATIVES. What suits me does not necessarily suit for every one. // Calculating binom propability //Old method: (Here the function "f" does the same thing as overloaded operator "!" pk =( f(n) / (f(k) * f(n-k))) * pow(p,k) * pow(1 - p,n-k) //New method: (Which one is harder to understand ??? :)) pk = (!n / (!k * !(n - k))) * p^k * (~p)^(n-k) Last but not least, where's > the beef ? Or what did I gain by using a number class ? > Tighter number controll... Meaning that: You can only do those things that have been defined (adding new methods is allowed in iheritance, removing is not possible..) Example in "Integer" class there should be defined function that computes n! Why ? Becourse you cannot compute n! for non-integers. Why does the "n!" return Number ? Becourse the result is always positive integer. Also, in additon for more controll there should be goal to eliminate most of those annoying type castings what you possibly have to normally do when playing with numbers.... "No matter how hard you try you cannot never satisfyi everybody..." traveler AT netti DOT fi