如何解决这个问题?
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:子项未定义
有什么办法可以处理这种情况吗?
我必须遵循以下示例性类型结构
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)
我该如何调用bla和blup实现init?例如,如果我想扩展超级类型方法