julia:OOP [英] julia: OOP or not
问题描述
我正在与Julia合作Juno。
I'm working on Juno with Julia.
我不知道Julia是否支持OOP。
I don't know if Julia suports OOP or not.
例如,是否有类似 class
或 struct
的c ++? br>
For example, is there something like class
or struct
of c++?
如何用数据或函数等成员声明它?
How to declare it with members such as a data or a function?
推荐答案
如有疑问,请阅读文档...
When in doubt, read the documentation...
http://docs.julialang.org/en/release-0.4/manual/types/#composite-types
长故事:
type MyType
a::Int64
b::Float64
end
x = MyType(3, 4)
x.a
EDIT:方法定义在类型定义之外,例如
Methods are defined outside the type definition, e.g.
function double(x::MyType)
x.a *= 2
end
方法do 不是住在类型中,例如,他们会在C ++或Python中做。这允许Julia的一个关键特性,即多重分派,也与用户定义的类型一起工作,这些类型与系统定义的类型完全相同。
Methods do not live inside the type, as they would do in C++ or Python, for example. This allows one of the key feature of Julia, multiple dispatch, to work also with user-defined types, which are on exactly the same level as system-defined types.
这篇关于julia:OOP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!