我使用的是自定义类型,当涉及指针时,我有一个问题,如下所示.
以下代码有效:
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)
}