Can't convert variables using __traits
Wusiki jeronii
wusikijeronii at gmail.com
Mon Apr 18 11:31:29 UTC 2022
Hello.
I can't change variable type using __traits.
Code:
```d
struct Users
{
public:
string login;
string name;
string email;
string icon;
int type;
}
void somefun()
{
string[string] test = ["login": "login"];
Users* user = new Users();
foreach (member; __traits(allMembers, Users))
if (member in test)
__traits(getMember, *user, member) =
to!(typeof(member))(test[member]);
}
```
I get the error:
> Error: cannot implicitly convert expression `to(test["type"])`
> of type `string` to `int`
Can anoyne explains to me why I can't convert traits member?
Without traits I can declare string variable and convert it to
int succesfully.
More information about the Digitalmars-d
mailing list