|
Kevin Gillette |
at Dec 4, 2013 at 7:58 pm
|
⇧ |
| |
The only difference between `struct { T }` and `struct { T T }` is that in
the first case, T's fields and methods are embedded in the top level struct
as a purely compile-time, syntactic convenience. There is no difference in
memory layout, speed of execution, etc. Since unnamed types such as
[]string (which is a slice, not an array) cannot have methods, then there
would be little or no potential benefit to embedding them, even if it were
allowed.
On Wednesday, December 4, 2013 12:37:04 PM UTC-7, Peter Ward wrote:
Is is possible to have an anonymous field in a struct, which is an array?
type Foo struct {
[]string
}
fails with "syntax error: unexpected ["
Whereas
type Foo struct {
Thingy []string
}
works fine.
Thanks in advance.
Pete
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit
https://groups.google.com/groups/opt_out.