To amplify a bit: Try
X[10] = struct(2,4) and then X[10].u = 3 --Peter On Monday, September 29, 2014 7:00:17 PM UTC-7, Stefan Karpinski wrote: > > The part that's throwing the error is X[10], not the ( ).u = 3 part – you > are trying to modify the .u field of a non-existent value. > > On Mon, Sep 29, 2014 at 9:54 PM, Greg Plowman <[email protected] > <javascript:>> wrote: > >> Hi, >> >> Just wanted further help or clarification on assigning to array of >> user-defined structure. >> >> Question was asked on Stack Overflow ( *Uninitialized arrays in Julia* >> <http://stackoverflow.com/questions/24416925/uninitialized-arrays-in-julia> >> ) >> >> type struct >> u::Int64 >> v::Int64 >> end >> >> X = Array(struct, 100) >> X[10].u = 3 >> >> will generate this error >> >> >> One answer states: >> >> You can assign values to uninitialized locations in arrays. You just >> can't extract values from uninitialized locations. >> >> >> >> However when I run this code (Julia v0.3.0), I get an error: >> >> ERROR: access to undefined reference >> in getindex at array.jl:246 >> >> I thought "X[10].u = 3" is assigning, not extracting? So why the error? >> >> Thanks, Greg >> >> >> >> >
