Re: [AD] C++ fix math

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


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Tuesday 13 August 2002 13:11, Vincent Penquerc'h wrote:
> It doesn't appear to me it achieves much here. Overloading
> can be useful sometimes, especially for operators, but there
> is no real advantage to having plenty of functions with the
> same name when it's not needed. So, I wanted to know whether
> this same name was needed, and if not, rename it to another
> name with a "fix" prefix.

Well, it could be useful in a template situation:

template<class T> class Angle {
    public:
        typedef T num_type;
    private:
        num_type _angle;
        Angle();
    public:
        template<class otherT> Angle(const Angle<otherT>&);
        num_type get_degrees();
        num_type get_radians();

        // here overloading comes into play
        num_type sin() { return sin(_angle); }
        num_type cos() { return cos(_angle); }
        // etc...
};

The overloaded function allows the template class to represent
fixed-point angles. In fact, template classes (such as the STL
containers) often have specifications such as:

 - the template argument must have copy constructor
 - some function f() must be defined for the template argument
 - etc.

Eric changed the constructors of the fix class to be explicit, thus
stopping implicit conversion and solving the problem.

Bye for now,
- --
Laurence Withers,  lwithers@xxxxxxxxxx
(GnuPG 04A646EA) http://www.lwithers.demon.co.uk/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)

iD8DBQE9WSQgUdhclgSmRuoRAsGUAJ4mN/muNOJeedLK7IwWxGa+E/HQvQCgm/ut
/GCLJysg9vcArth1ybSLNxA=
=1dpt
-----END PGP SIGNATURE-----



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