How get struct value by member name string ?

John Xu 728308756 at qq.com
Tue May 30 01:24:46 UTC 2023


On Monday, 29 May 2023 at 11:21:11 UTC, Adam D Ruppe wrote:
> On Monday, 29 May 2023 at 09:35:11 UTC, John Xu wrote:
>>     Error: variable `column` cannot be read at compile time
>
> you should generally getMember on a variable
>
> T t;
> __traits(getMember, t, "name")
>
> like that, that's as if you wrote t.name

It seems I can't use variable as member name:

     struct T {int a; string name;}
     T t;
     string s = "name";
     writeln(__traits(getMember, t, s));

Above code fails to compile. Any help?


More information about the Digitalmars-d-learn mailing list