首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >为什么我不能将*Struct赋值给*接口?

为什么我不能将*Struct赋值给*接口?
EN

Stack Overflow用户
提问于 2012-11-22 18:55:51
回答 2查看 65.6K关注 0票数 152

我只是在处理Go tour,我对指针和接口感到困惑。为什么这段Go代码不能编译?

package main

type Interface interface {}

type Struct struct {}

func main() {
    var ps *Struct
    var pi *Interface
    pi = ps

    _, _ = pi, ps
}

也就是说,如果StructInterface,为什么*Struct不是*Interface

我得到的错误消息是:

prog.go:10: cannot use ps (type *Struct) as type *Interface in assignment:
        *Interface is pointer to interface, not interface
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13511203

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档