Well, I want to test the object is save in the map by copying it or just a reference to the original object, so I did a test, but it seems Golang doesn't allow direct access to get the address of object in map by it's index. Code as follow:
package main
import "fmt"
type Student struct {
name string
age int
}
func main() {
s := Student{name: "charlie", age: 18}
fmt.Printf("%p\n", &s)
m := make(map[int]Student)
m[0] = s
fmt.Printf("%p\n", &m[0]) //I want to see if the object saved in the map is a reference to object or just a copy of it, but I got compile error here, showing "cannot take the address of m[0]"
}
Can someone explains it ?
1) why this operation is not allowed?
2) Is that some special restriction when using the map?