# Outer constructors with a field of static vector

**URL:** <https://discourse.julialang.org/t/outer-constructors-with-a-field-of-static-vector/38415>\
**Category:** New to Julia\
**Created:** [April 29, 2020, 10:07am UTC](https://discourse.julialang.org/t/outer-constructors-with-a-field-of-static-vector/38415 "2020-04-29T10:07:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vadim\_Zotin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vadim_zotin/32/10774_2.png) [@Vadim\_Zotin](https://discourse.julialang.org/u/Vadim_Zotin)\
**Post date:** [April 29, 2020, 10:07am UTC](https://discourse.julialang.org/t/outer-constructors-with-a-field-of-static-vector/38415/1 "2020-04-29T10:07:08Z")

</div>

Dear all,

Can you help me to clarify some point?

Suppose, I have two composite types, one of them is parametric. They look rather similar.

using StaticArrays  
struct test1  
t::SVector{5,AbstractFloat}  
end

struct test2{T\<:AbstractFloat}  
t::SVector{5,T}  
end

The constructor test1 can convert a vector to a static vector while making the object.

test1([1.0:5.0…])  
test1(AbstractFloat[1.0, 2.0, 3.0, 4.0, 5.0])

test2 can’t

test2([1.0:5.0…])  
ERROR: MethodError: no method matching test2(::Array{Float64,1})  
Closest candidates are:  
test2(::SArray{Tuple{5},T\<:AbstractFloat,1,5}) where T\<:AbstractFloat at REPL[4]:2.

What is the cause of this difference?

---

<div class="post-metadata">

**Author:** ![jishnub](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jishnub/32/33620_2.png) [@jishnub](https://discourse.julialang.org/u/jishnub)\
**Post date:** [April 29, 2020, 11:56am UTC](https://discourse.julialang.org/t/outer-constructors-with-a-field-of-static-vector/38415/2 "2020-04-29T11:56:49Z")

</div>

The default constructors generated seem different.

```julia
julia> methods(test1)
# 2 methods for type constructor:
[1] test1(t::SArray{Tuple{5},AbstractFloat,1,5}) in Main at REPL[6]:2
[2] test1(t) in Main at REPL[6]:2

julia> methods(test2)
# 1 method for type constructor:
[1] (::Type{test2})(t::SArray{Tuple{5},T,1,5}) where T<:AbstractFloat in Main at REPL[7]:2

```

`test1` has an extra method that can convert any type to an `SArray`, while `test2` doesn’t. You can add your own though:

```julia
julia> test2(v::AbstractVector{T}) where {T<:AbstractFloat} = test2{T}(SVector{5,T}(v))
test2

julia> test2([1.0:5.0...])
test2{Float64}([1.0, 2.0, 3.0, 4.0, 5.0])

```

---

<div class="post-metadata">

**Author:** ![Vadim\_Zotin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vadim_zotin/32/10774_2.png) [@Vadim\_Zotin](https://discourse.julialang.org/u/Vadim_Zotin)\
**Post date:** [April 29, 2020, 1:08pm UTC](https://discourse.julialang.org/t/outer-constructors-with-a-field-of-static-vector/38415/3 "2020-04-29T13:08:32Z")

</div>

Thank you so much!
