Struct cross dependency

Hello,

There is something new about struct cross dependency?

mutable struct Father
    child::Child
end

mutable struct Child
    father::Father
end

Why not this?

abstract type AbstractChild end

mutable struct Parent{C<:AbstractChild}
    child::C
end

mutable struct Child <: AbstractChild
    parent::Parent{Child}
    Child() = new()
end

Then you can do

c = Child(); p = Parent(c); c.parent = p; # create them

c.parent === p && p.child === c # true

(c, p) # do something with them
2 Likes

Hi @FedericoStra,

I didn’t know this feature: incomplete initialization.

I will study it to be able to see if it solves my real problem.

Thank you.