Boost logo

Boost :

From: Olivier Grant (olivier.grant_at_[hidden])
Date: 2006-09-21 08:09:51


I agree on your point, on the other hand, you can do this :

   class vector3d
   {
   public:
      float x, y, z;

      float operator[]( int index ) const
      { return ((float *)this)[index]; }

      float & operator[]( int index )
      { return ((float *)this)[index]; }

      /* ... */
   };

in which case "v.x" and "v[0]" are the same thing. this is what I currently
have. Now some people will argument its a hack maybe.

Olivier.

On 9/21/06, Theodore Papadopoulo <Theodore.Papadopoulo_at_[hidden]>
wrote:
>
> On Wed, 2006-09-20 at 17:48 +0100, Olivier Grant wrote:
>
> > > > Right now I have three simple vector classes - ranging from vector2d
> to
> > > > vector4d - that are not templetized since I like the idea of being
> able
> > > to
> > > > access coordinates directly by their name
>
> Unfortunately, this is not the best choice. As sson as you will have to
> iterate through the coordinates, you will find that having an array is
> necessary (at least if you do not want to have an awful efficiency....).
>
> Theo.
>
> _______________________________________________
> Unsubscribe & other changes:
> http://lists.boost.org/mailman/listinfo.cgi/boost
>


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk