我正在使用自定义类型,当涉及如下指针时,我遇到了问题。
以下代码有效:
package main
import (
"fmt"
)
type deck []string
func newDeck(cards ...string) deck {
return cards
}
下面的代码也是有效的:
package main
func str(n []string) *[]string {
return &n
}
以下代码无效。为什么这样?我必须写一个类型转换return (*deck)(&cards)
package main
import (
"fmt"
)
type deck []string
func newDeck(cards ...string) *deck {
return &cards // compiles with return (*deck)(&cards)
}
呼如林
Smart猫小萌
随时随地看视频慕课网APP
相关分类