Why is my structure template does not compile?

Weed resume755 at mail.ru
Thu Dec 11 15:55:10 PST 2008


BCS пишет:
> Reply to Denis,
> 
>> On Fri, 12 Dec 2008 02:21:11 +0300, BCS <ao at pathlink.com> wrote:
>>
>>> Reply to Weed,
>>>
>>>> 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.
>>>
>> No, I don't think so. Don't confuse 'Element' with 'data'. Element is
>> a type, it doesn't have a length property. But it does have sizeof (an
>> example of Element is an 'int', which is 4 bytes long).
>>
> 
> Oh, fud. I did get that wrong. I still think it's wrong as I'm not sure 
> anything has 0 sizeof and even then that should be static assert.


You are right.

It happens that the verification Element not null. static assert would 
be better.


More information about the Digitalmars-d-learn mailing list