Methods

Automatic addressing of receivers

If v is addressable and the method set of &v contains the method, the call can use implicit addressing. A map element or ordinary function result is not addressable; convenience at the call site does not change the method set of T. Example output: '3'.

Formal Syntax & Structure

go syntaxgo
v.PointerMethod()

Working Example

Example Snippetgo
package main
import "fmt"
type Count int
func (n *Count) Inc() { *n++ }func main() {  n := Count(2)  n.Inc()  fmt.Println(n)}
Go Reference