"Lazy" initialization of structs
Daniel Tan Fook Hao via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu Jun 1 05:04:05 PDT 2017
Somehow this code works for me:
```D
auto error (int status, string description){
struct Error {
int status;
string description;
}
Error err = {
status,
description
};
return err.serializeToJson;
}
```
which is supposed to be the same as
```D
struct Error {
int status;
string description;
}
auto error (int status, string description){
Error err = {
status,
description
};
return err.serializeToJson;
}
```
If I'm reading this right, in the former, the struct is created
when the function is called in run-time, and the type is then
inferred after that? I don't really understand the behavior
behind this.
More information about the Digitalmars-d-learn
mailing list