我是 Golang 世界的新手。我試圖理解自動引用的概念。我對以下程序的困惑?第一個和第二個有什么區別函數 main 的第一行age(20).print()二三線myAge := age(20)myAge.print()完整程序如下:package mainimport "fmt"type age uint8func (a *age) print() { fmt.Println(a)}func main() { age(20).print() // this line throws error // however, the below line works properly myAge := age(20) myAge.print()}請幫助理解這兩種方法之間的區別。我假設他們都是一樣的。
Golang 自動引用,并不總是可以得到一個值的地址
慕碼人8056858
2022-06-13 15:36:45