Reputation: 11
So the following works:
type Individual [][]int
type Population []*Individual
What I'm trying to do is add a field to Population so I do the following
var p Population
p.Name = "human"
So I tried this:
type Individual [][]int
type Population struct {
[]*Individual
Name string
}
But it doesn't work for me. How do I do this?
Upvotes: 0
Views: 58
Reputation: 44360
You should declare a name for the field of your struct:
package main
import (
"fmt"
)
type Individual [][]int
type Population struct {
Individual []*Individual // <- A name for field
Name string
}
func main() {
var p Population
p.Name = "human"
fmt.Printf("%+v", p)
}
=> {Individual:[] Name:human}
Upvotes: 1