Struct in my package cannot be called correctly

My package structure:

module DoubleRFs

export ParDBRF

struct ParDBRF # params of double rf
    # ===== To be prepared =====
    v1::Float64
    r::Float64
    ϕs::Float64
    ϕ2s::Float64
    h1::Int64
    h::Int64
    circum::Float64
    centerenergy::Float64
    αc::Float64
    ξ::Float64
    νy::Float64
    σδ::Float64
    # ===== Calculated automatically ======
    ωβ::Float64
    ω0::Float64
    ωξ::Float64
    γ::Float64
    η::Float64
    # ===== inner constructor ======
    Param(v1, r, ϕs, ϕ2s, h1, h, circum, centerenergy, αc, ξ, νy, σδ)=new(v1, r, ϕs, ϕ2s, h1, h, circum, centerenergy, αc, ξ, νy, σδ, νy*2*π*299792458.0/circum, 2*π*299792458.0/circum, νy*2*π*299792458.0/circum*ξ/(αc-1/(centerenergy/0.511e6)^2), centerenergy/0.511e6, αc-1/(centerenergy/0.511e6)^2)
end
Base.broadcastable(x::ParDBRF) = Ref(x)

end

When I called this struct, an error was reported:

> param=DoubleRFs.ParDBRF(3639505.370587, 0.1833, 2.0399026, 5.708, 756, 3, 1360.4, 6e9, 0.0000156073, 0.0, 106.27, 1.06e-3)
MethodError: no method matching DoubleRFs.ParDBRF(::Float64, ::Float64, ::Float64, ::Float64, ::Int64, ::Int64, ::Float64, ::Float64, ::Float64, ::Float64, ::Float64, ::Float64)

Stacktrace:
 [1] top-level scope
   @ In[3]:1
 [2] eval
   @ .\boot.jl:360 [inlined]
 [3] include_string(mapexpr::typeof(REPL.softscope), mod::Module, code::String, filename::String)
   @ Base .\loading.jl:1116

You have defined a function as an inner constructor, removing the default constructors. Note that you’ve used a different name for that than the name of the struct.

Thanks, but inner constructor is really convenient. If I remove this constructor, is there an alternative?

use an outer constructor

1 Like

Thank you.