On 2012-11-15 20:32, Era Scarecrow wrote:

  Hmmm... Correct me if I'm wrong, but you can create/use opAssign,
correct? Although that doesn't work during initialization...

struct MyInt
{
   int i;
   ref MyInt opAssign(int rhs) {
     i = rhs;
     return this;
   }
}

MyInt x = MyInt(10);
MyInt y; // = 15; //cannot implicity convert
y = 15;

That's what a construtor is for:

struct MyInt
{
    int i;

    this (int i)
    {
        this.i = i;
    }

    ref MyInt opAssign(int rhs) {
        i = rhs;
        return this;
    }
}

void main()
{
    MyInt i = 3;
}

--
/Jacob Carlborg

Reply via email to