如何在Golang中将自定义类型切片强制转换为原始切片?

问题描述 投票:0回答:1
type TCustomIntType int

func aFunc() {
    var fails []TCustomIntType = []TCustomIntType([]int{})
}

我有:

cannot convert []int literal (type []int) to type []TCustomIntType

怎么解决?我是否必须手动编写转换功能?

go slice custom-type
1个回答
2
投票

是的,您必须使用for循环手动复制它。

© www.soinside.com 2019 - 2024. All rights reserved.