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

Drug Drug2004 at bk.ru
Sun Feb 9 00:15:47 UTC 2020


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


More information about the Digitalmars-d-learn mailing list