鉴于这些类型定义:
type N interface{ ~int | ~float32 | ~float64 }
type S[T any] struct {
t T
}
type myInt int
type pSpMyInt[T myInt] *S[*T]
type spMyInt[T *myInt,] S[T]
type spMyInt2[T myInt] S[*T]
type pSpMyInt我可以创建一个 var
func createPS[T myInt]() pSpMyInt[T] {
var i T
s := S[*T]{t: &i}
return &s
}
但我无法弄清楚如何创建spMyIntor的变量spMyInt2。
这
func createSP[T myInt]() spMyInt2[T] {
var i T
s := S[*T]{t: &i}
return s
}
编译失败 cannot use s (variable of type S[*T]) as type spMyInt2[T] in return statement。
潇湘沐
相关分类