du6333137 2014-09-18 03:03
浏览 1537
已采纳

如何在Golang中使用其他文件中的其他struct方法

I have a file called login.go and account.go

In login.go

func (api *ApiResource) test() {
   fmt.Println("Works!")
}

In account.go I have:

func main () {
   Res := new(ApiResource)
   Res.test()
}

Buit I'm getting undefined:test error.

They both use package main and are on same src/ folder

What do I need to fix here?

  • 写回答

1条回答 默认 最新

  • dpbrrczhlwbv849228 2014-09-18 03:34
    关注

    If you used go run then you must pass both files to like go run login.go account.go.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?