# Structs: Able to change members of type Vector{Float64}, but not of type Float64

**URL:** <https://discourse.julialang.org/t/structs-able-to-change-members-of-type-vector-float64-but-not-of-type-float64/78221>\
**Category:** General Usage\
**Tags:** question\
**Created:** [March 21, 2022, 3:14pm UTC](https://discourse.julialang.org/t/structs-able-to-change-members-of-type-vector-float64-but-not-of-type-float64/78221 "2022-03-21T15:14:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Christian\_Brunbjerg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/christian_brunbjerg/32/34243_2.png) [@Christian\_Brunbjerg](https://discourse.julialang.org/u/Christian_Brunbjerg)\
**Post date:** [March 21, 2022, 3:14pm UTC](https://discourse.julialang.org/t/structs-able-to-change-members-of-type-vector-float64-but-not-of-type-float64/78221/1 "2022-03-21T15:14:58Z")

</div>

Hello! 🙂

When using an struct I am able to change the values inside members that are of type Vector, but I cannot not do it for members of type Float64. Do I need to change my struct to an immutable struct or is there a way around this? I would prefer not to use a mutable struct, since I need as much performance as possible. I have created an example below to illustrate my point.

```julia
#Initializing struct
struct test
    A::Float64
    B::Vector{Float64}
end

#Creating entry
example = test(1.0, [1.1, 1.2, 1.3])

#Changing a value in member B
example.B[2] = 5.0
println(example.B)

```

5.0

```julia
example.A = 2.0

```

ERROR: setfield!: immutable struct of type test cannot be changed  
Stacktrace:  
[1] setproperty!(x::test, f::Symbol, v::Float64)  
@ Base .\Base.jl:43  
[2] top-level scope  
@ REPL[401]:1

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [March 21, 2022, 3:18pm UTC](https://discourse.julialang.org/t/structs-able-to-change-members-of-type-vector-float64-but-not-of-type-float64/78221/2 "2022-03-21T15:18:28Z")

</div>

> [@Christian\_Brunbjerg](#):
>
> `example.A = 2.0`

you’re literally mutating your struct so you need mutable struct.

in `example.B`, it’s different because `.B` still points to the same vector, you’re mutating the vector, not `example` itself.

---

<div class="post-metadata">

**Author:** ![Christian\_Brunbjerg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/christian_brunbjerg/32/34243_2.png) [@Christian\_Brunbjerg](https://discourse.julialang.org/u/Christian_Brunbjerg)\
**Post date:** [March 21, 2022, 3:21pm UTC](https://discourse.julialang.org/t/structs-able-to-change-members-of-type-vector-float64-but-not-of-type-float64/78221/3 "2022-03-21T15:21:10Z")

</div>

Okay I see thank you. I understand was is meant by mutable now. Have a nice day!
