Why is my structure template does not compile?

BCS ao at pathlink.com
Thu Dec 11 15:21:11 PST 2008


Reply to Weed,


> ref Element opIndex( in uint n )
> {
> return data[n];
> }

> ref Element opIndexAssign( in Element a, in uint n )
> {
> data[n] += a;
> return data[n];
> }

I'm guessing as I don't use 2.0 but I think that this is a bug. DMD is trying 
to say that the above returns are trying to return something that can't be 
referenced (like a math expression result).

> invariant()
> {
> // If I comment out next line compilation goes smoothly:
> assert( Element.sizeof > 0 );
> }


OTOH that assert is wrong. Element.sizeof will always return 8, the size 
of an array reference. What you want is Element.length.




More information about the Digitalmars-d-learn mailing list