我了解到julia没有class,但是我又需要类似class的结构
试着用struct来完成,下面的只是示例,完整的struct,field比下面的多很多,所以这样写起来就很麻烦,也不方便维护struct的field,有办法写的简洁些吗?
struct P1
M::Int8
Ks::Int8
metric::String
end
struct P2
D::Int16
Ds::Int16
k_v::Int64
function P2(D,k_v)
Ds = D*k_v
new(D, Ds, k_v)
end
end
struct C
M::Int8
Ks::Int8
metric::String
D::Int16
Ds::Int16
k_v::Int64
function C(M, Ks, metric, D, k_v)
p1 = P1(M, Ks, metric)
M, Ks, metric = p1.M, p1.Ks, p1.metric
p2 = P2(D, k_v)
D, Ds, k_v = p2.D, p2.Ds, p2.k_v
new(M, Ks, metric, D, Ds, k_v)
end
end
提前感谢任何的帮助或建议。