By Reference
BlitzMax Forums/BlitzMax Programming/By Reference
| ||
Can I pass a variable by reference to a function? Docs don't say but it seems to be by value only. |
| ||
Use the Var keyword in the parameter section of the Function declaration.Local a:Int = 10 Doubler a Print a Function Doubler(a:Int Var) a:* 2 End Function |
| ||
Thank you RAFF |
| ||
Also, note that objects are always passed by reference. |
| ||
that is weird when I tested it, it treated it by value |
| ||
hmmmm var does work for "by reference" Local x:Float = 20 For Local i:Int = 0 To 10 inc(x) Print i+"> "+x Next Function inc( i:Float Var ) i:+1 End Function |
| ||
you can pass objects by value or by refrence, and it does make a differenceType tguy Field name$ End Type Local joe:tguy Global bob:tguy joe=New tguy joe.name="joe" bob=New tguy bob.name="bob" change(joe) Print joe.name change2(joe) Print joe.name Function change(guy:tguy) 'does nothing guy=bob End Function Function change2(guy:tguy Var) guy=bob End Function |