> What would the following CFML code display to the user? > > cfset Temp=StructNew() > cfset Temp["First"]=40 > cfset Second=StructCopy(Temp) > cfset Second["First"]=80 > cfoutput #Evaluate(Second["First"] + Temp["First"])# /cfoutput > > my answer was 160, but according to the book, the answer is 120. I > thought (and it says in Forta's book) that a copy of a structure is > just a pointer to the original so that if you change the copy, you > change the original.
When you use the StructCopy or Duplicate functions to copy a structure, it copies the structure by value - creating a separate object. If you don't use one of those functions when you copy, you copy by reference, creating a pointer. The code below would copy by reference: <cfset Second = Temp> Dave Watts, CTO, Fig Leaf Software http://www.figleaf.com/ phone: (202) 797-5496 fax: (202) 797-5444 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Get the mailserver that powers this list at http://www.coolfusion.com FAQ: http://www.thenetprofits.co.uk/coldfusion/faq Archives: http://www.mail-archive.com/[email protected]/ Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists

