opAssign work not with initialisation?

spir denis.spir at gmail.com
Sat Dec 18 06:43:08 PST 2010


On Sat, 18 Dec 2010 13:08:14 +0000
Adam Burton <adz21c at gmail.com> wrote:

> > struct S {
> >     int value;
> >     void opAssign(int value) {
> >         this.value = value;
> >     }
> > }
> > unittest {
> >     S s1;
> >     s1 = 3;	// OK
> >     S s2 = 3;   // _build_  error
> > }
> > ==>
> > Element.d(105): Error: cannot implicitly convert expression (3) of type
> > int to S

> That compiles for me. I am running 2.050 on linux.

Does not with dmd 2.049 on (ubuntu) Linux. If it's solved in 2.050, then let us let down.

> As a work-around try "S 
> s2 = S(3)", failing that then try adding a constructor that accepts an int 
> (opAssign is only used during assignment, not construction).

;-) Sure, but this bypasses opAssign and assigns .value directly, I guess. What do you think?

Denis
-- -- -- -- -- -- --
vit esse estrany ☣

spir.wikidot.com



More information about the Digitalmars-d-learn mailing list