.sizeof for classes

Frank Benoit frank at nix.de
Mon Mar 27 10:58:06 PST 2006


How to get the size of an object?

class Test
{
	uint[10] a;
}

void main()
{
	Test t = new Test;

	assert( Test.sizeof == 4 );
	assert( t.sizeof == 4 );
	assert( Test.classinfo.init.length == 48 );

}

static assert( Test.classinfo.init.length == 48 ); // is not evaluatable
at compile time.


Isn't this syntax weird?
How can I get the size at compile time?



More information about the Digitalmars-d mailing list