Can't convert variables using __traits [CLOSED]
Wusiki jeronii
wusikijeronii at gmail.com
Mon Apr 18 14:24:46 UTC 2022
On Monday, 18 April 2022 at 12:20:11 UTC, Krzysztof Jajeśnica
wrote:
> On Monday, 18 April 2022 at 11:31:29 UTC, Wusiki jeronii wrote:
>> [...]
>
> Hello,
> the error happens because `__traits(allMembers)` doesn't return
> actual struct members, it returns their names as `string`s.
> Because of that `typeof(member)` will always return `string`,
> and your code becomes equivalent to:
> ```d
> foreach(member; __traits(allMembers, Users))
> if(member in test)
> __traits(getMember, *user, member) =
> to!string(test[member]);
> ```
> then the compiler sees that you're attempting to assign a
> `string` to `user.type` and gives an implicit conversion error.
>
> [...]
Oohh. I've understood. Thanks
More information about the Digitalmars-d
mailing list