dstbp22002 2016-12-02 22:11
浏览 32
已采纳

在进行中,如果我们要使用该文件中定义的功能,是否不需要在同一目录中导入另一个文件?

in go, don't we need to import another file in same directory if we want to use function defined in that file? For example.

FolderA-
-------- FileA.go
---------FileB.go

In FileB.go, I define method Foo()

In FileA.go, I want to call Foo() which defined in FileB.go.

Do I need to import FileB in FileA.go like this?

import ("FileB")
  • 写回答

2条回答 默认 最新

  • douluohan3403 2016-12-02 22:17
    关注

    No. Just call a function. Please note:

    • You are not including files in Go, you include packages.
    • These files should share the package.

    Check this: https://blog.golang.org/organizing-go-code

    And google is full of good info as well, ex. http://thenewstack.io/understanding-golang-packages/

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统