du16178 2017-12-29 04:31
浏览 395
已采纳

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

type TCustomIntType int

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

I got:

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

How to fix it? Do I have to write a convert func manually?

  • 写回答

1条回答 默认 最新

  • doujia5863 2017-12-29 04:52
    关注

    Yes, you have to copy it manually with a for loop.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?