opAssign in mixins
Max Samukha
samukha at voliacable.com_nospam
Sat Dec 16 04:40:28 PST 2006
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");
}
More information about the Digitalmars-d
mailing list