将结构指针转换为 Golang 中的接口指针

我有一个功能


func doStuff(inout *interface{}) {

   ...

}

此函数的目的是能够将任何类型的指针视为输入。但是当我想用结构的指针调用它时,我有一个错误。


type MyStruct struct {

    f1 int

}

打电话时 doStuff


ms := MyStruct{1}

doStuff(&ms)

我有


test.go:38: cannot use &ms (type *MyStruct) as type **interface {} in argument to doStuff

我如何投射&ms才能与 兼容*interface{}?


明月笑刀无情
浏览 214回答 1
1回答
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Go