On Sun, 2003-09-21 at 16:29, Richard Chapman wrote:
> hi
>
> how do you make sure a variable a vector in this case: is passed by value as
> opposed to passed by reference.
>
> i have a class and in the class i have a list of positions, now i have a
> function called addposition which takes in a item called pos. in the
> function call i set pos=shape.pos, but when i move my shape.pos to something
> else eg shape.pos + vector(1,1,1) it changes all the positions i entered
> into the list to this value.
>
> how do i stop this happening
>
> thanks
>
> richard
You can create a copy explicitly like this:
arr = arrow( pos=vector(1,2,3))
vec = vector( arr.pos)
arr.pos -= vector(1,0,0)
arr.pos will be equal to vector(0,2,3) and vec will equal vector(1,2,3).
HTH,
Jonathan Brandmeyer
|