Structs as keys in Go maps

前端 未结 2 1728
自闭症患者
自闭症患者 2021-02-04 00:10

I was looking into using structs as keys in golang maps. A field in this struct is supposed to be a map also and this seems to go against the documentation provided here which s

2条回答
  •  故里飘歌
    2021-02-04 00:45

    In your example the map key is a pointer to the struct, not the struct itself. Pointers can be compared for equality even when the items they point to can't be compared. This comparison is not based on the contents of the item, but only on its memory address.

提交回复
热议问题