【发布时间】:2019-07-07 06:47:25
【问题描述】:
我想去掉下面代码中的变量 temp:
type myinterface interface {
f1()
}
type a struct {
val int
}
type b struct {
mi *myinterface
}
func (a) f1() {
}
func demo() {
a1 := a{3}
var temp myinterface = a1
b1 := b{&temp}
fmt.Println(b1)
但是如果我试着写
b1 := b{&myinterface(a1)}
我收到消息
无法获取myinterface(a1)的地址(未定义)
这样做的正确方法是什么?
更新:
我没有指向接口的指针,因为接口可以保存结构或指向结构的指针,正如这个问题中所详述的:
【问题讨论】:
标签: pointers go casting temporary