Is there a way to get the size of a class object statically?
Denis Koroskin
2korden at gmail.com
Mon Oct 5 03:19:49 PDT 2009
On Mon, 05 Oct 2009 14:13:06 +0400, Nick Sabalausky <a at a.a> wrote:
> "Andrei Alexandrescu" <SeeWebsiteForEmail at erdani.org> wrote in message
> news:hac4pl$1s2e$1 at digitalmars.com...
>> I figured out a way to get the offsetof any member statically:
>>
>> class A {
>> char a;
>> int b;
>> char c;
>> }
>>
>> void main()
>> {
>> int[A.init.a.offsetof] x;
>> }
>>
>> Unfortunately, I can't figure a way to get the class' size statically.
>> This doesn't work:
>>
>> int[A.classinfo.init.length] x;
>>
>> Any way to fetch the size of A?
>>
>
> sizeof(A) doesn't work?
>
>
sizeof(A) doesn't compile.
A.sizeof == Object.sizeof == (void*).sizeof
More information about the Digitalmars-d
mailing list