@tomtom wrote:
I have a composite type which as a field of type
Function
, how could this function access other fields of struct?struct Adder adds::Vector{Float64} f::Function Adder(v::AbstractVector{Float64}) = new(v, (x, i) -> x + adds[i] ) end julia> obj = Adder([1.0, 2.0] ) Adder([1.0, 2.0], var"#5#6"()) julia> obj.f.([10.0, 20.0], 1:2) ERROR: UndefVarError: adds not defined
to be concrete, in the above MWE, how could
f()
access the field variableadds
? thanks.
Posts: 3
Participants: 2