Default struct constructors if a struct member is a union
Basile B.
b2.temp at gmx.com
Sun Jun 30 00:05:00 UTC 2024
On Saturday, 29 June 2024 at 23:33:41 UTC, solidstate1991 wrote:
> [...]
> My question is can I initialize structs like these in one line
> without relying on a second line? My usecase scenario doesn't
> really allow constructors for the struct, since it's a binding
> to an external library via C API.
Apprently that works with an anonymous union:
```d
enum TypeEnum {
Integer32,
Integer64,
Float32,
Float64,
}
struct S {
TypeEnum type;
union {
int i32;
long i64;
float f32;
double f64;
}
}
S foo0 = S(TypeEnum.Integer32, 20);
S foo1 = S(TypeEnum.Integer64, 20L);
```
More information about the Digitalmars-d-learn
mailing list