# Need help with MethodError: ambigous

**URL:** <https://discourse.julialang.org/t/need-help-with-methoderror-ambigous/9051>\
**Category:** New to Julia\
**Created:** [February 14, 2018, 8:49am UTC](https://discourse.julialang.org/t/need-help-with-methoderror-ambigous/9051 "2018-02-14T08:49:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![QUANG\_VU\_NGUY\_N\_PH\_M](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/quang_vu_nguy_n_ph_m/32/14299_2.png) [@QUANG\_VU\_NGUY\_N\_PH\_M](https://discourse.julialang.org/u/QUANG_VU_NGUY_N_PH_M)\
**Post date:** [February 14, 2018, 8:49am UTC](https://discourse.julialang.org/t/need-help-with-methoderror-ambigous/9051/1 "2018-02-14T08:49:11Z")

</div>

How to solve this “ambigous” problem by fixing the syntax?

```julia
julia> struct Element
              a::Vector

              function Element(x::Vector)
                      new(x)
              end
       end

julia> function (elt_type::Type{T})(pts::Vector{Int}) where T<:Element
                 2
        end

julia> Element([1,3])
ERROR: MethodError: Element(::Array{Int64,1}) is ambiguous. Candidates:
  (elt_type::Type{T})(pts::Array{Int64,1}) where T<:Element in Main at REPL[2]:2
  Element(x::Array{T,1} where T) in Main at REPL[1]:5
Possible fix, define
  Element(::Array{Int64,1})

```

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [February 14, 2018, 8:55am UTC](https://discourse.julialang.org/t/need-help-with-methoderror-ambigous/9051/2 "2018-02-14T08:55:32Z")

</div>

Is this what you mean?

```julia
julia> struct Element
           a::Vector

           function Element(x::Vector)
               new(x)
           end
       end

julia> Element(pts::Vector{Int}) = 2
Element

julia> Element([1,3])
2

```

---

<div class="post-metadata">

**Author:** ![QUANG\_VU\_NGUY\_N\_PH\_M](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/quang_vu_nguy_n_ph_m/32/14299_2.png) [@QUANG\_VU\_NGUY\_N\_PH\_M](https://discourse.julialang.org/u/QUANG_VU_NGUY_N_PH_M)\
**Post date:** [February 14, 2018, 9:07am UTC](https://discourse.julialang.org/t/need-help-with-methoderror-ambigous/9051/3 "2018-02-14T09:07:03Z")

</div>

I am sorry, the upper is my simplied version of the bellow code. How to fix it with your idea above?

```julia
julia> struct Element{DIM,N}
                    a::Int
                    b::Vector
                    function Element{DIM,N}(connectivity::Vector) where {DIM,N}
                         new(3, connectivity)
                   end
        end

julia> struct Point
                idx::Int
                coord::Vector{Float64}
                weight::Float64
       end

julia> function (elt_type::Type{T})(pts::Vector{Point}) where T<:Element
                 2
       end

julia> pts1 = Point(1, [23.0, 21.0, 32.0], 4.0);

julia> pts2 = Point(45, [23, 21, 2], 1.0);

julia> r = [pts1, pts2]
2-element Array{Point,1}:
 Point(1, [23.0, 21.0, 32.0], 4.0)
 Point(45, [23.0, 21.0, 2.0], 1.0)

julia> Element{2,4}(r)
ERROR: MethodError: Element{2,4}(::Array{Point,1}) is ambiguous. Candidates:
  (elt_type::Type{T})(pts::Array{Point,1}) where T<:Element in Main at REPL[3]:2
  (::Type{Element{DIM,N}})(connectivity::Array{T,1} where T) where {DIM, N} in Main at REPL[1]:5
Possible fix, define
  (::Type{Element{DIM,N}})(::Array{Point,1})

```

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [February 14, 2018, 9:44am UTC](https://discourse.julialang.org/t/need-help-with-methoderror-ambigous/9051/4 "2018-02-14T09:44:31Z")

</div>

Replace

```julia
function (elt_type::Type{T})(pts::Vector{Point}) where T<:Element
                 2
       end

```

with

```julia
function Element{DIM,N}(connectivity::Vector{Point}) where {DIM,N}
    2
end

```

maybe?

```julia
julia> Element{2,4}(r)
2

```
