# Default values for nested struct array

**URL:** <https://discourse.julialang.org/t/default-values-for-nested-struct-array/79072>\
**Category:** New to Julia\
**Tags:** question\
**Created:** [April 5, 2022, 8:57pm UTC](https://discourse.julialang.org/t/default-values-for-nested-struct-array/79072 "2022-04-05T20:57:14Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![james3](https://avatars.discourse-cdn.com/v4/letter/j/b5e925/32.png) [@james3](https://discourse.julialang.org/u/james3)\
**Post date:** [April 5, 2022, 8:57pm UTC](https://discourse.julialang.org/t/default-values-for-nested-struct-array/79072/1 "2022-04-05T20:57:14Z")

</div>

I can’t work out how to specify default values for a struct array that is nested. I have one struct `a_t` which specifies default values. I have a MVector of type `a_t` in the struct `b_t`. The following code fails. I want the MVector `b2` of type `a_t` to take the default values already specified. (Note that if I did not have a vector, e.g. `b2::a_t = a_t()`, then that works as expected.)

```julia
using StaticArrays
using Parameters

@with_kw mutable struct a_t
    a1::Int64 = 10
    a2::Float64 = 0.0
end

@with_kw mutable struct b_t
    b1::Float64 = 0.0
    b2::MVector{2, a_t} .= a_t()
end

```

---

<div class="post-metadata">

**Author:** ![stillyslalom](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stillyslalom/32/45687_2.png) [@stillyslalom](https://discourse.julialang.org/u/stillyslalom)\
**Post date:** [April 5, 2022, 9:08pm UTC](https://discourse.julialang.org/t/default-values-for-nested-struct-array/79072/2 "2022-04-05T21:08:56Z")

</div>

```julia
Base.@kwdef mutable struct b_t
    b1::Float64 = 0.0
    b2::MVector{2, a_t} = @MVector [a_t() for _ = 1:2]
end

```
