pass-by-reference

Arguments to delegate.BeginInvoke are copies or references?

Where is there documentation on the treatment of arguments to BeginInvoke? If I have a delegate (which wraps my handler function) that accepts an object as a parameter, does that object get copied or referenced by the asynchronously-called handler function? delegate void MyDelegate(SomeObject obj); // later on: // invoke the delegate ...

Java static method parameters

Why does the following code return 100 100 1 1 1 and not 100 1 1 1 1 ? public class Hotel { private int roomNr; public Hotel(int roomNr) { this.roomNr = roomNr; } public int getRoomNr() { return this.roomNr; } static Hotel doStuff(Hotel hotel) { hotel = new Hotel(1); return hotel; } public static void main(String arg...

pass variable by reference within class? in php

I'm working on a hex color class where you can change the color values of any hex code color. In my example, I haven't finished the hex math, but it's not completely relevant to what I'm explaining here. Naively, I wanted to start to do something that I don't think can be done. I wanted to pass object properties in a method call. Is th...

When you need pass by reference in Java to assign values to multiple parameters, how do you do it?

In order to refactor some methods into smaller ones, I need pass by reference, since I can only have one return type. I could create a different return or parameter type whenever I need to do this, but then I'd end up with a bunch of bloated, seemingly unnecessary classes. What is the best alternative here, besides redesigning the progr...

.click() callback references local variable from the calling method instead of copying by value

The following jQuery Javascript code is included on an otherwise empty page. var element; $(function() { for (var i = 0; i < 10; i++) { element = $('<div>' + i + '</div>'); element.click(function() { alert(i); }); $('body').append(element); } }); The desired behavior is that this code should generate 10 div e...

JNA unsigned integer by reference gives strange results

I'm currently trying to access a C API using JNA. But I have a problem with unsigned integer parameters that are being passed by reference. So here is the C function in question: int EE_DataGetNumberOfSample(DataHandle hData, unsigned int* nSampleOut); In Java I have: public int EE_DataGetNumberOfSample(Pointer hData, ByReference nS...

Passing optional parameter by reference in c++

I'm having a problem with optional function parameter in C++ What I'm trying to do is to write function with optional parameter which is passed by reference, so that I can use it in two ways (1) and (2), but on (2) I don't really care what is the value of mFoobar. I've tried such a code: void foo(double &bar, double &foobar = NULL) {...

Passing objects by reference or not in C#

Suppose I have a class like this: public class ThingManager { List<SomeClass> ItemList; public void AddToList (SomeClass Item) { ItemList.Add(Item); } public void ProcessListItems() { // go through list one item at a time, get item from list, // modify item according to class' purpose ...

C++ Type error with Object versus Object reference

I have the following function (which worked in Visual Studio): bool Plane::contains(Vector& point){ return normalVector.dotProduct(point - position) < -doubleResolution; } When I compile it using g++ version 4.1.2 , I get the following error: Plane.cpp: In member function âvirtual bool Plane::contains(Vector&)â: Plane.cpp:36: er...

How can I modify a scalar reference passed to a subroutine reference?

I have a function to convert documents into different formats, which then calls another function based on the type document. It's pretty straight forward for everything aside from HTML documents which require a bit of cleaning up, and that cleaning up is different based on where it's come from. So I had the idea that I could pass a refer...

Why does UdpClient.Receive require a ref parameter?

Why is the parameter on UpdClient.Receive a ref parameter, instead of simply out? According to the MSDN page, the parameter is filled with the address that the datagram was sent from. However it doesn't specify what kind of input it is used for, only output. ...

g++ doesn't think I'm passing a reference

When I call a method that takes a reference, g++ complains that I'm not passing a reference. I thought that the caller didn't have to do anything different for PBR. Here's the offending code: //method definition void addVertexInfo(VertexInfo &vi){vertexInstances.push_back(vi);} //method call: sharedVertices[index]->addVertexInfo(Ver...

Is it right to move all responsibility for cloning objects to user of a library?

I'm not that knowledgeable in this matter so I decided to ask here. Let's say we have some 'library' in Ruby (or any other pass by reference scripting language): class Moo attr_accessor :bar def initialize self end end a = 'a string' b = Moo.new b.bar = a b.bar will obviously be the same object as a. Is it right ...

Should the argument be passed by reference in this .net example?

I have used Java, C++, .Net. (in that order). When asked about by-value vs. by-ref on interviews, I have always done well on that question ... perhaps because nobody went in-depth on it. Now I know that I do not see the whole picture. I was looking at this section of code written by someone else: XmlDocument doc = new XmlDocument(); Ap...

Powershell / .Net: Get a reference to an object returned by a method

I am teaching myself PowerShell by writing a simple parser. I use the .Net framework class Collections.Stack. I want to modify the object at the top of the stack in place. I know I can pop() the object off, modify it, and then push() it back on, but that strikes me as inelegant. First, I tried this: $stk = new-object Collections.Sta...

PHP performance difference between passing variables method

Hi everyone, Will there be any measurable performance difference when passing data as values instead of as reference in PHP? It seems like few people are aware of that variables can be passed as values instead of references. Is this common sense or not? ...

Is there a language with native pass-by-reference/pass-by-name semantics, which could be used in modern production applications?

Hi! This is a reopened question. I look for a language and supporting platform for it, where the language could have pass-by-reference or pass-by-name semantics by default. I know the history a little, that there were Algol, Fortran and there still is C++ which could make it possible; but, basically, what I look for is something more mo...

Passing arguments by value or by reference in objective C

Hello, I'm kind of new with objective c and I'm trying to pass an argument by reference but is behaving like it were a value. Do you know why this doesn't work? This is the function: - (void) checkRedColorText:(UILabel *)labelToChange { NSComparisonResult startLaterThanEnd = [startDate compare:endDate]; if (startLaterThanEnd ==...

What (are there any) languages with only pass-by-reference?

Hello, I was wondering. Are there languages that use only pass-by-reference as its eval strategy? Thank you. ...

Saving a reference to a int.

Here is a much simplified version of what I am trying to do static void Main(string[] args) { int test = 0; int test2 = 0; Test A = new Test(ref test); Test B = new Test(ref test); Test C = new Test(ref test2); A.write(); //Writes 1 should write 1 B.write(); //Writes 1 should write 2 C.write(); //Writes 1...