gpt4 book ai didi

go - "Cannot use myType as type interface{}"?我以为在 Go 中所有类型都算作 interface{}?

转载 作者:数据小太阳 更新时间:2023-10-29 03:40:52 24 4
gpt4 key购买 nike

我正在尝试编写一个可以采用任何类型的函数(更具体地说,试图让它采用任何类型的 protobuffer,但如果必须的话,我会接受更广泛的通用性)。根据我读过的内容,似乎可以这样做:

func processSlice(mySlice []interface{}) void{
// Do stuff in here
}

但是,当我尝试将其与一片原型(prototype)一起使用时,出现以下错误:

cannot use myProtoSlice (type []*MyProto) as type []interface{} in argument to processSlice

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com