首页 文章
  • -1 votes
     answers
     views

    Golang界面和*界面

    我正在尝试在我的代码库中更多地使用接口,用于我正在编写的游戏服务器,并理解高级概念以及何时应该使用(我认为) . 在我的情况下,我使用它们将我的包彼此分离,以及使测试更容易 . 我的问题归结为我有一个具有ptr接收方法的结构 . 然后我通过接口将此结构传递给另一个函数,就像在这个_757891中一样 . 我很困惑为什么带有类型接口的参数的函数可以接受实现该接口的地址 . 为什么不 func som...
  • -1 votes
     answers
     views

    如何将接口传递给具有大量参数的方法

    我编写了一个惰性代码来演示我必须实现接口的问题 . 我有方法M1,M2,它将struct X作为参数并且具有struct Y的类型 . 我希望所有这些方法都由单个接口I实现 . 问题是实现我需要知道的接口的方法M需要传递给子方法的参数(M1,M2) . 我收到错误: <argument name> used as a value 当我在M中传递多个参数时 type Y struct {...
  • 3 votes
     answers
     views

    转到界面返回类型

    我有这样的界面: type ViewInterface interface{ Init() View } type View struct{ Width int Height int } 所以我从View创建了一个新类型 type MainView View func (m MainView) Init() MainView{ return MainView{ ...
  • 5 votes
     answers
     views

    接口和指针接收器

    我是新手gopher,并试图让我的头围绕指针接收器和接口 . type Foo interface { foo() } type Bar struct {} func (b *Bar) foo() {} 基于以上定义.. --- Allowed --------- b := Bar{} b.foo() --- Not allowed ----- var foo Foo = Bar{...

热门问题