【发布时间】:2020-10-16 17:50:59
【问题描述】:
我是 Golang 世界的新手。我试图理解自动引用的概念。
我对以下程序的困惑?第一个和第二个有什么区别
- main 函数的第一行
age(20).print()
- 二三线
myAge := age(20)
myAge.print()
完整程序如下:
package main
import "fmt"
type age uint8
func (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()
}
请帮助理解这两种方法之间的区别。我假设它们都是一样的。
【问题讨论】:
标签: pointers go types reference