Re: [Fwd: Re: [AD] C++ fix math]

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


Gillius wrote:

> float y = 15.6;
> float x = cos( y );
> 
> I don't see anything about Fix in there.  It's not explicit.
> 
> ObjectA x ( 15 );
> ObjectB y ( 20 );
> ObjectB z = x + y;
> 
> This is explicit.  I don't expect SomeOtherCompletelyUnrelatedClass's 
> function to be called here.  Hmm maybe this is why the Java creators took 
> out implicit conversions and operator overloading...

Right. I don't care which solution is taken, but one thing is certain
for me: 

float y = 3.0;
float x = cos(y);

should _not_ call Fix::cos. I realize this will only happen if you
leave out the math.h header, but it still seems bad. I can live with
either solution though: explicit constructors sounds ok, although I
personally think making cos a static member function of Fix would look
best, as it leaves no doubt (ever) as to which cos function is
being used.

float x = Fix::cos(y);

seems quite reasonable to me, and is no longer ambiguous: it is now
clear you want y to be converted to a Fix first, as Fix::cos doesn't
accept floats.

Hein Zelle

>-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-< 
 Unix is user friendly. It's just very particular about who 
 it's friends are.

 Hein Zelle                     hein@xxxxxxxxxx
	                        http://www.icce.rug.nl/~hein
>-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-<



Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/