opAssign work not with initialisation?
Adam Burton
adz21c at gmail.com
Sat Dec 18 05:08:14 PST 2010
spir wrote:
> Hello,
>
> 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
>
> Do I miss something? And why not a compile-time error?
>
>
> Thank you,
> Denis
> -- -- -- -- -- -- --
> vit esse estrany ☣
>
> spir.wikidot.com
That compiles for me. I am running 2.050 on linux. 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).
More information about the Digitalmars-d-learn
mailing list