Why can I not create the following, with an anonymous field?
type T1 struct { T1_Text string } type T2 struct { T2_Text string T1 }
used in func ..
t := T2{ T2_Text: "Test", T1{T1_Text: "Test"}, }
Gives me: mixture of field:value and value initializers?
A brief explanation.
The reason you get that is because you are allowed to only use one of the two types of initializers and not both.
i.e. you can either use field:value or value.
Using your example you either do
field:value
t := T2{ T2_Text: "Test", T1: T1{T1_Text: "Test"}, }
or only values
t := T2{ "Test", T1{"Test"}, }
Hope that explains the why
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With