6. Pointer Receiver Code
type circle struct {
x int
y int
radius int
}
func (c *circle) grow() {
c.radius *= 2
}
func main() {
c := circle{
x: 1,
y: 2,
radius: 4,
}
// notice c is not a pointer in the calling function
// but the method still gains access to a pointer to c
c.grow()
fmt.Println(c.radius)
// prints 8
}Go Pointer Receiver - Automatic Conversion Notes
The Key Concept
Example Breakdown
What Go Does Automatically
Both Work the Same
Why This Matters
Complete Example
The Reverse Also Works
Summary of Auto-Conversions
Method Type
Call On
What Go Does
Key Takeaways
1
2
3
4
5