www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Multiple alias for multiple functions?

reply "Borislav Kosharov" <boby_dsm abv.bg> writes:
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?
Aug 08 2013
parent "anonymous" <anonymous example.com> writes:
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; } }
Aug 08 2013