Quantcast
Channel: First steps - JuliaLang
Viewing all articles
Browse latest Browse all 2795

Import struct from other module as a parameter

$
0
0

I’ve following dir structure:

-> Calc (root dir)
        -> src
            -> Calc.jl
            -> Controls.jl
            -> Models.jl

Below are the content of the files:
Calc.jl:

module Calc

    include("Models.jl")
    include("Controls.jl")

    export Models,Controls

end # module

Models.jl

module Models
    struct Position{P <: Real}
        x::P
        y::P
    end

    struct Size{P <: Int}
        width::P
        height::P
    end
    struct Widget{N <: String,P <: Position,S <: Size}
        name::N
        postion::P
        size::S
    end
end

Controls.jl

module Controls
    move_up!(widget::Models.Widget, velocity) = widget.position.x + velocity
end

I get errors when I try to add Widget as a parameter to my function defined in Controls.jl file.

How can I properly define my parameter ?

Please note the following constraints:

  • Should use Modules
  • Should not merge Controls and Models content in one single file

Please help thanks

7 posts - 2 participants

Read full topic


Viewing all articles
Browse latest Browse all 2795

Trending Articles