# Reference/Mutation Problem

**URL:** <https://discourse.julialang.org/t/reference-mutation-problem/7983>\
**Category:** General Usage\
**Created:** [December 25, 2017, 10:14am UTC](https://discourse.julialang.org/t/reference-mutation-problem/7983 "2017-12-25T10:14:10Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Qiyamah](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/qiyamah/32/2660_2.png) [@Qiyamah](https://discourse.julialang.org/u/Qiyamah)\
**Post date:** [December 25, 2017, 10:14am UTC](https://discourse.julialang.org/t/reference-mutation-problem/7983/1 "2017-12-25T10:14:10Z")

</div>

Hi guys

I am trying to do the following:

```nohighlight
abstract type Operator end;

mutable struct Multiply <: Operator
 multiplier::Float64
end

mutable struct Incrementor <: Operator
   inc::Int
end 

mutable struct CompositeOp <:Operator
  mulr::Multiplier
  incr::Incrementor
end
  
c = CompositeOp(Multiply(2.2), Incrementor(3))

```

I want

```nohighlight
c.multiplier
c.inc

```

to return 2.2 and 3 respectively and when i make an assignment to those the values in mulr and incr to change accordingly .how can i do something like this using setfield!, getfield and maps?  
Or another solution is welcome.

Thanks

---

<div class="post-metadata">

**Author:** ![thofma](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/thofma/32/1691_2.png) [@thofma](https://discourse.julialang.org/u/thofma)\
**Post date:** [December 25, 2017, 10:29am UTC](https://discourse.julialang.org/t/reference-mutation-problem/7983/2 "2017-12-25T10:29:35Z")

</div>

It appears you want a type where you can change the binding of the fields. You should try `mutable struct` instead of `struct`.

See also [https://docs.julialang.org/en/stable/manual/types/#Mutable-Composite-Types-1](https://docs.julialang.org/en/stable/manual/types/#Mutable-Composite-Types-1)

---

<div class="post-metadata">

**Author:** ![Qiyamah](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/qiyamah/32/2660_2.png) [@Qiyamah](https://discourse.julialang.org/u/Qiyamah)\
**Post date:** [December 25, 2017, 10:37am UTC](https://discourse.julialang.org/t/reference-mutation-problem/7983/3 "2017-12-25T10:37:34Z")

</div>

Sorry i forgot to put mutable keyword in front of structs…

---

<div class="post-metadata">

**Author:** ![Qiyamah](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/qiyamah/32/2660_2.png) [@Qiyamah](https://discourse.julialang.org/u/Qiyamah)\
**Post date:** [December 26, 2017, 6:25am UTC](https://discourse.julialang.org/t/reference-mutation-problem/7983/4 "2017-12-26T06:25:05Z")

</div>

Anyone? Any Suggestions?

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [December 26, 2017, 6:29am UTC](https://discourse.julialang.org/t/reference-mutation-problem/7983/5 "2017-12-26T06:29:35Z")

</div>

In v0.6 you can make functions like `change_multiplier(c,...)`. In v0.7 there’s getfield overloading.
