Skip to content

Multiple Dispatch can Implement Object Oriented (but not visa versa)

Dehann Fourie edited this page Nov 19, 2021 · 1 revision
function sumUtil(state, args...)
  @info "sumUtil" length(state) args
  sum(state)
end

struct MyClass
  # public object state
  state::Vector{Float64}

  # member functions
  sumValues::Function

  MyClass(;state=randn(10)) = new(state, (args...)->sumUtil(state, args...))
end



obj = MyClass();

obj.sumValues("Hello world")