Multiple alias for multiple functions?

anonymous anonymous at example.com
Thu Aug 8 13:25:05 PDT 2013


On Thursday, 8 August 2013 at 20:14:58 UTC, Borislav Kosharov 
wrote:
> I want to make a simple Vector struct class:
>
> struct Vector {
>     alias _data this;
>     alias data!0 x, width;
>     alias data!1 y, height;
>
> private:
>     @property float data(int i)() {
>         return _data[i];
>     }
>
>     @property void data(int i)(float value) {
>         _data[i] = value;
>     }
>
>     float[2] _data;
> }
>
> But I get two similar errors:
> Vector.data matches more than one template declaration, 
> vector.d(9):data(int i)() and vector.d(13):data(int i)(float 
> value)
>
> I see that it might cause problems to have ambiguous aliases, 
> but does anyone know how I might implement this? Should I 
> remove the struct and just make @property x for float[2] and 
> the others?

     template data(int i) {
         @property float data() {
             return _data[i];
         }

         @property void data(float value) {
             _data[i] = value;
         }
     }


More information about the Digitalmars-d mailing list