Pointers to Maps in Go
In Go, maps are reference types, meaning that they are stored in memory by their address. When assigning a map to a variable, the variable holds a reference to the actual map in memory. Attempting to obtain a pointer to a map using the '&' operator (&valueToSomeType) is unnecessary as maps are already passed by reference.
What Went Wrong?
The compiler error mentioned in the original question ("internal compiler error: var without type, init: new"), indicating a separate issue, unrelated to using pointers.
Usage
To access the map using the reference variable, simply use the square bracket notation:
valueFromMap := valueToSomeType[number]
This will retrieve the value associated with the provided key from the map that is referenced by the valueTo variable.
The above is the detailed content of Do I Need Pointers to Access Maps in Go?. For more information, please follow other related articles on the PHP Chinese website!