pass-by-reference

Return code or out parameter?

I'm making a method to fetch a list of filenames from a server but I have come to a problem that I cannot answer. The method returns two things: an SftpResult which is an enum with a variety of return codes. the list of filenames. Of these three signatures: public static ArrayList GetFileList(string directory, out SftpResult resu...

Consequences of only using stack in C++

Lets say I know a guy who is new to C++. He does not pass around pointers (rightly so) but he refuses to pass by reference. He uses pass by value always. Reason being that he feels that "passing objects by reference is a sign of a broken design". The program is a small graphics program and most of the passing in question is mathematical...

Seemingly impossible PHP variable referencing behavior when using Memcached's set method

I have a rather weird problem. Because of a certain PECL bug, I pass a var into memcached and it gets changed. The suggested workaround is to pass $data.'' instead of $data and that destroys the reference. But that won't work for me because I don't just pass strings into memcached, I pass all data types. So I ended up assigning a new v...

Swap two strings in java, by passing them to a utility function, but without returning objects or using wrapper classes.

I am trying to swap two strings in Java. I never really understood "strings are immutable". I understand in theory but never came across it in practice. Also, since String is an object in Java and not a primitive type, I don't understand why the following code prints the same result twice, instead of interchanging the words! public sta...

Actionscript pass by reference

package { import flash.display.Sprite; public class test1 extends Sprite { private var tmp:Object; public function test1() { createObj(tmp); if(tmp == null) { trace("nothing changed"); } } private function createObj(obj:Object):void { obj = new Object(); } } } In the above code the output on the console is : nothin...

C++ passing reference to class' private variable - compiler issue?

Is the passing by reference of a private variable in a class to be directly changed outside that class acceptable practice? Or is this something that the compiler 'should' pick up and prevent? Example: //------------------------------------------- class Others { public: Others() {}; void ChangeIt(string &str) { str = "Changed by Othe...

Is it always better to use pass by reference in C++ ?

Possible Duplicates: const T &arg vs. T arg How to pass objects to functions in C++? I used the following code to ascertain that C++ on passing objects as const reference the compiler does not make a copy of the object and send the copy. The output confirmed that passing object as const reference does not involve making a co...

C++ Pointer problem

I'm having a pointer problem that I can't seem to figure out. It seems like I've used pointers in this way a 1000 times so I'm not quite sure what is going on here. I have the following code: int iRetVal; CycleCountOrder* cycleOrder = NULL; CycleCountLineItem* cycleLine = NULL; iRetVal = m_CycleCount.GetCCOrderLine(pOneLocation.szO...

Are values in LINQ expressions passed by reference?

I'm reading manning book about LINQ, and there is an example: static class QueryReuse { static double Square(double n) { Console.WriteLine("Computing Square("+n+")..."); return Math.Pow(n, 2); } public static void Main() { int[] numbers = {1, 2, 3}; var query...

JavaScript - How to make an array that contains objects by reference?

Hi, I'm using JavaScript Mapping Library - OpenLayer to create a markers overlay. I want to control the markers dynamically: add new ones and remove existing markers from the layer. the way to add a new marker to the layer is by the command: markers.addMarker(new OpenLayers.Marker(new OpenLayers.LonLat(0,0),icon)); as you can see, t...

Need clarification on how Session actually works?

At a lot of places I have seen the following pattern. Consider the code: Customer cust = (Customer) Session["Customer"]; //Do something to the object cust Session["Customer"] = cust and the code : Customer cust = (Customer) Cache["Customer"]; //do something to object cust Cache["Customer"] = cust; Now, in the second case, putti...

Advanced Java topics for a C# programmer

I'm a C# programmer writing Java (for Android) and have a few technicalities of Java I'm still not sure about, and worried I'm approaching from a C# angle: Are parameters in methods passed in the same manner as C#? (Copied for reference types) Why has the @Override attribute suddenly appeared (I think it's Java 1.5+?) How is possible t...

How to pass a variable by reference when creating an object in php

So I want to extend for example this RecursiveIterator from the SPL with the function each so i can easily walk over the object/array class it extends RecursiveArrayIterator { public function each( $function, $args=array() ){ $args = (sizeof($args)>0) ? array_merge(array($this),(array)$args) : array($this); iterator_...

Passing object to method in java appears to be by reference (and Java is by val)

I thought when you passed objects to methods in Java, they were supposed to be by value. Here is my code: public class MyClass{ int mRows; int mCols; Tile mTiles[][]; //Custom class //Constructor public MyClass(Tile[][] tiles, int rows, int cols) { mRows = rows; mCols = cols; mTiles = n...

Howto do reference to ints by name in Python

I want to have a a reference that reads as "whatever variable of name 'x' is pointing to" with ints so that it behaves as: >>> a = 1 >>> b = 2 >>> c = (a, b) >>> c (1, 2) >>> a = 3 >>> c (3, 2) I know I could do something similar with lists by doing: >>> a = [1] >>> b = [2] >>> c = (a, b) >>> c ([1], [2]) >>> a[0] = 3 >>> c ([3], [2]...

php ::Array references...

Hi guys, any idea why foreach ($groups as &$group) $group = trim(str_replace(',', '', $group)); echo '<pre>'; print_r($groups); echo '</pre>'; $groupsq = $groups; foreach ($groupsq as &$group) $group = '\'' . $group . '\''; echo '<pre>'; print_r($groups); echo '</pre>'; Yields Array ( [0] => Fake group [1] => another ...

Passing Pointer of vector of pointers... no no?

New to C++ and its giving me a hissy fit. The actual code is on a different computer and I can't copy it, so I'll do the best I can with pseudo code. My endgame is to have a vector [of pointers] that can be accessed by several different objects. The way I attempted to go about this is have the original class that contains the vector to...

Recursive function not returning a value in PHP

I've got a recursive function defined as follows private function _buildPathwayRecurse(&$category, &$reversePathway = array()) { $category->uri = FlexicontentHelperRoute::getCategoryRoute($category->id); $reversePathway[] = $category; if ($category->parent_id != 0) { $category = $this->_getCatForPathway($category->parent_id);...

How can I use PDL rcols in a subroutine with pass-by-reference?

Specifically, I want to use rcols with the PERLCOLS option. Here's what I want to do: my @array; getColumn(\@array, $file, 4); # get the fourth column from file I can do it if I use \@array, but for backward compatibility I'd prefer not to do this. Here's how I'd do it using an array-ref-ref: sub getColumn { my ($arefref, $f...

Nullify object passed to a function

I have the following problem with objects in actionscript3: var o:Object = new Object(); destroyObject(o); trace(o); // [object Object] function destroyObject(obj:Object):void{ obj = null; trace(obj); // null } Since objects are passed by reference in AS3 I assume that the previous code would change o to null, but it doesn't. ...