我在 SO 上发现了类似的问题,但似乎都没有给出适合我的情况的答案。
我有几个模块,在其中一个模块中我创建了一个可变结构,我希望能够在其他模块中使用它。所有文件都在同一级别:
- file_module_A.jl
- file_module_B.jl
- file_module_C.jl
在 file_module_A.jl 中:
module A
mutable struct MyType
variable
end
end
在 file_module_B.jl 中:
module B
# I need to import MyType here
end
在 file_module_C.jl 中:
module C
# I need to import MyType here
end
我尝试了以下方法但没有成功:
- 直接使用:
using .A
不起作用 - 我不能使用:
include("./file_module_A.jl")
在 B 和 C 中,因为当它们相互交互时,我得到错误 can't convert from Main.BA to Main.CA becauseinclude
include a copy of the entire code
有任何想法吗?提前致谢!