Is there a way to get the size of a class object statically?

Max Samukha spambox at d-coding.com
Mon Oct 5 00:13:12 PDT 2009


On Mon, 05 Oct 2009 01:47:21 -0500, Andrei Alexandrescu
<SeeWebsiteForEmail at erdani.org> wrote:

>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?
>
>
>Andrei

__traits(classInstanceSize, A)



More information about the Digitalmars-d mailing list