can anyone tell me why the following code does not work as (I) expected?
I have a simple type Cell which only has an index and a origin array.
When creating multiple instances of this Cell type in a loop and assigning
different origin arrays to them, in the end all instances have the same
origin array. I am using julia 0.3
(It does work if the commented line is un-commented though..)
type Cell
index::Int64
origin::Array{Int64,1}
end
nDim = int(3)
nCells = int(2)
cellList = Array(Cell, nCells)
oVector = Array(Int64, nDim) # does not work as expected
#oVector = Array(Float64, nDim) # does work
for i=1:nCells
for j=1:nDim
oVector[j] = i
end
cellList[i] = Cell(i, oVector)
end
# after the loop, both cells have same origin...
println(cellList[1].index, ": ", cellList[1].origin)
println(cellList[2].index, ": ", cellList[2].origin)
thanks in advance
andre