Setting members of structs in Cxx.jl

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!

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

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).

1 Like

Works thank you!