Arrays of User Types

Using Julia 1.0, I am creating a mutable struct XX with two Float64 fields, x and y. I then use AA = fill(XX(100.0,200.0),10) to create an Array of type XX. However, when i type AA[1].x = 300.0, it seems to change the x value for the entire array. Is there a better way to do this?

That puts the same XX object in every slot of the array. If you want a different XX object in each slot of the array, you can do something like this:

AA = [XX(0.0, 0.0) for _ = 1:10]
1 Like

Thank you for your help! I do appreciate it very much. Your suggestion works beautifully.