# Setting members of structs in Cxx.jl

**URL:** https://discourse.julialang.org/t/setting-members-of-structs-in-cxx-jl/2260
**Category:** General Usage
**Tags:** cxx
**Created:** [February 23, 2017, 10:53pm UTC](https://discourse.julialang.org/t/setting-members-of-structs-in-cxx-jl/2260 "2017-02-23T22:53:56Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![rcnlee](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rcnlee/32/4107_2.png) [@rcnlee](https://discourse.julialang.org/u/rcnlee)
#### Post date: [February 23, 2017, 10:53pm UTC](https://discourse.julialang.org/t/setting-members-of-structs-in-cxx-jl/2260/1 "2017-02-23T22:53:56Z")

</div>

Hello,

In Cxx.jl, I can create structs and read values of members, but is there a way to set the value of a member directly, i.e., without creating a setter function?

> obj = @cxxnew MyStruct() #create instance  
> xval = @cxx obj-\>x #read member value  
> @cxx obj-\>x = 5.0 #how to set? this doesn’t work

Thanks!

---

<div class="post-metadata">

### Author: ![Keno](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/keno/32/285_2.png) [@Keno](https://discourse.julialang.org/u/Keno)
#### Post date: [February 23, 2017, 10:56pm UTC](https://discourse.julialang.org/t/setting-members-of-structs-in-cxx-jl/2260/2 "2017-02-23T22:56:08Z")

</div>

Generally the string macros are preferred for anything non-trivial, so you’ll want something like:

```julia
y = 5.0
icxx"$obj->x = $y;"

```

(y being a variable for illustrative purposes only, you can of course put the 5.0 in there directly).

---

<div class="post-metadata">

### Author: ![rcnlee](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rcnlee/32/4107_2.png) [@rcnlee](https://discourse.julialang.org/u/rcnlee)
#### Post date: [February 23, 2017, 11:54pm UTC](https://discourse.julialang.org/t/setting-members-of-structs-in-cxx-jl/2260/3 "2017-02-23T23:54:33Z")

</div>

Works thank you!
