Getting the initial value of a class field in compile time.

realhet real_het at hotmail.com
Sun Feb 9 00:39:30 UTC 2020


On Sunday, 9 February 2020 at 00:15:47 UTC, Drug wrote:
> On Saturday, 8 February 2020 at 23:37:56 UTC, realhet wrote:
>> Hello,
>>
>> class A{
>>   int i = 42;
>> }
>>
>> Is there a way to get that 42? (Input is the class A and the 
>> name of the field 'i')
>>
>> A.i.init returns 0, so it doesn't care about the class.
>>
>> classinfo.m_init can be an option, but maybe there's a nicer 
>> way to do this?
>>
>> Thx!
>
> Try A.init.i

I tried and A.init.stringof == "void()"

That generates a new question, what is void() ?
It has no sizeof property.
I guess it's the voidest of the voids in D :D


More information about the Digitalmars-d-learn mailing list