December 16, 2006 opAssign in mixins | ||||
---|---|---|---|---|
| ||||
Can anybody tell me if the following should work? template TProp(T) { T _value; T opAssign(T v) { _value = v; return v; } } class Test { mixin TProp!(int) intProp; mixin TProp!(char[]) stringProp; } void main() { auto test = new Test; test.intProp = 1; test.stringProp = "A value"; } The compiler outputs: test.d(12): function test.Test.TProp!(int).opAssign conflicts with test.Test.TProp!(char[]).opAssign at test.d(12) test.d(12): function test.main.TProp!(int).opAssign conflicts with test.main.TProp!(char[]).opAssign at test.d(12) It is semantically equivalent to the working code which creates no conflicts: template TProp(T) { T _value; T set(T v) { _value = v; return v; } } class Test { mixin TProp!(int) intProp; mixin TProp!(char[]) stringProp; } void main() { auto test = new Test; test.intProp.set(1); test.stringProp.set("A value"); } |
Copyright © 1999-2021 by the D Language Foundation