There is a type of Company, which is a structure containing a Person's map, which are also all structures.
type Company struct { employees map[int]Person } type Person struct { [...] }
After allocating some Person to the employee map, I try to call the pointer method for each of them.
func (company *Company) Populate(names []string) { for i := 1; i <= 15; i++ { company.employees[i] = Person{names[i - 1], [...]} company.employees[i].Initialize() } }
This terribly fails when the go compiler complains that I cannot call the pointer methods on company.employees [i] and I cannot use the address company.employees [i]. However, setting the Initialize method to a method without pointers and letting it return a copy of the person and assigning it to the map again using
company.employees[i] = company.employees[i].Initialize()
it works, which is not so different.
Not working with pointers, it really hurts me. The map is not immutable, and they are modified in any case, so calling the method of a pointer to an object on the map should not be a problem - at least in my head.
If someone could explain to me what I'm doing wrong here - or correct my thinking - I would be pleased.
source share