小编Ohm*_*Ohm的帖子

朱莉娅:循环引用

如何解决这个问题?

mutable struct Parent
    name::String
    children::Vector{Child}

    function Parent(name)
        return new(name)

    end

end

mutable struct Child
    name::String
    parent::Parent

    function Child(name)
        return new(name)

    end

end

parent = Parent("father")
child = Child("son")
Run Code Online (Sandbox Code Playgroud)

产生错误

LoadError:UndefVarError:子项未定义

有什么办法可以处理这种情况吗?

julia

3
推荐指数
1
解决办法
1358
查看次数

如何调用超类型方法?

我必须遵循以下示例性类型结构

abstract type bla end
abstract type blup <: bla end

mutable struct Ablup <: blup
   a::Real
end

mutable struct Bblup <: blup
    b::Real
end


init(obj::bla) = println("bla")
init(obj::blup) = println("blup")
init(obj::Ablup) = println("Ablup")
init(obj::Bblup) = println("Bblup")

testA = Ablup(1)
testB = Bblup(1)

init(testA)
init(testB)
Run Code Online (Sandbox Code Playgroud)

我该如何调用blablup实现init?例如,如果我想扩展超级类型方法

inheritance types julia

3
推荐指数
1
解决办法
37
查看次数

标签 统计

julia ×2

inheritance ×1

types ×1