Why is my structure template does not compile?
Weed
resume755 at mail.ru
Thu Dec 11 15:09:05 PST 2008
struct S( Element )
{
Element[] data;
this( in uint len )
{
data.length = len;
}
ref Element opIndex( in uint n )
{
return data[n];
}
ref Element opIndexAssign( in Element a, in uint n )
{
data[n] += a;
return data[n];
}
invariant()
{
// If I comment out next line compilation goes smoothly:
assert( Element.sizeof > 0 );
}
}
void main()
{
alias S!(double) st;
st test = st(20);
auto a = test[2];
test[2] = 3;
}
compilation error:
$ dmd demostruct
Error: __result = this is not an lvalue
demostruct.d(12): Error: __result = (this.data[n]) is not an lvalue
demostruct.d(18): Error: __result = (this.data[n]) is not an lvalue
demostruct.d(29): template instance demostruct.S!(double) error
instantiating
More information about the Digitalmars-d-learn
mailing list