我在 go 中进行移位操作时遇到错误,invalid operation: 1 << bucketCntBits (shift count type int, must be unsigned integer)尝试在 go inside main()body 中声明文字时出错失败文字示例:https://play.golang.org/p/EqI-yag5yPp
func main() {
bucketCntBits := 3 // <---- This doesn't work
bucketCnt := 1 << bucketCntBits
fmt.Println("Hello, playground", bucketCnt)
}
当我将班次计数声明为常量时,班次运算符就起作用了。工作常量示例:https ://play.golang.org/p/XRLL4FR8ZEl
const (
bucketCntBits = 3 // <---- This works
)
func main() {
bucketCnt := 1 << bucketCntBits
fmt.Println("Hello, playground", bucketCnt)
}
为什么常量可以工作,而文字却不能用于移位运算符?
慕容3067478
慕标5832272
慕雪6442864
相关分类