|
Boost : |
From: Marcus Lindblom (macke_at_[hidden])
Date: 2006-09-22 03:17:03
Olivier Grant wrote:
> 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.
>
I've sometimes done just:
class vector3d
{
public:
float x, y, z;
float operator[]( int index ) const
{ return (&x)[index]; }
/* ... */
};
/Marcus
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk