Questions tagged [pass-by-reference]

Pass by reference is an argument marshalling strategy whereby a variable's location in memory is passed to a function, rather than a copy of the variable's value, although the function appears in the source code to receive the variable itself rather than a pointer to it.

Passing by reference means that the memory address of a variable is passed rather than a copy of the variable's value.

This typically means that the function can modify the passed variable, assigning a new value to it. However for performance reasons, passing by reference may be useful even if the passed structure is not modified, as with the Pascal var modifier, and some programming languages have constructs (like the C const modifier) to disallow modification of a variable passed by reference.

4485 questions
1
vote
3 answers

Most Efficient Way to Use Singleton Classes

In C++, I use a singleton class and refer to the only instance in another class. I'm wondering what is the most efficient way to access this instance since it is a large data structure. I considered these things. Getting a reference from the…
Izza
  • 2,389
  • 8
  • 38
  • 60
1
vote
3 answers

Java Array pass-by-reference

I have this code: public static int MAX; public static int MIN; public static void startGame(){ MIN = -1; MAX = 1; int[] randomGridVals = new int[ROWS*COLUMNS]; fill(randomGridVals); …
Cemre Mengü
  • 18,062
  • 27
  • 111
  • 169
1
vote
3 answers

javascript alternative to strict evaluation

I am making an javascript game, featuring several levels, stored in json. When loading, I run a function to "parse" the level object by replacing values that are not present by their default values, or by replacing some values by objects, such…
Zelenova
  • 276
  • 3
  • 7
1
vote
1 answer

Can we pass the parameter array by reference to call_user_func_array() instead of passing an array of variable references?

I've looked at Is it possible to pass parameters by reference using call_user_func_array()?, and http://php.net/manual/en/function.call-user-func-array.php. The approved technique for passing by reference using call_user_func_array() seems to be by…
Shaun Dychko
  • 825
  • 1
  • 9
  • 11
1
vote
6 answers

php passing by reference not working

I'm just trying to understand passing by reference in PHP by trying some examples found on php.net. I have one example right here found on the php website but it does not work: function foo(&$var) { return $var++; } $a=5; echo foo($a); // Am I…
user765368
  • 19,590
  • 27
  • 96
  • 167
1
vote
2 answers

How do I pass a Generic::List by reference?

In an attempt to wrap some unmanaged code in a managed .dll I'm trying to convert a Generic::List of data points into a std::vector. Here's a snippet of what I'm trying to do: namespace ManagedDLL { public ref class CppClass { void…
Jon Cage
  • 36,366
  • 38
  • 137
  • 215
1
vote
0 answers

Emulating pass by reference in JavaScript

All my unit tests have some common code I can run and abstract into a function. However I want to be able to re-use the Core value in every test function makeSuite(name, module, callback) { suite(name, function () { var Core = {}; …
Raynos
  • 166,823
  • 56
  • 351
  • 396
1
vote
2 answers

Javascript pass by object by reference then update

I've been searching all over SO and I know there are a lot of topics about this but I haven't found one that answered my question. I saw a question about getting an object value back from a string like this: function getPropertyByString(str) { …
blong824
  • 3,920
  • 14
  • 54
  • 75
1
vote
2 answers

Pass by Reference vs Returning class instance

As per title is there any difference passing a reference type to a method such as: public void GetStream(Stream outputStream) { outputStream.Write(data); } VS public Stream GetStream() { MemoryStream ms = new MemoryStream(); …
Fixer
  • 5,985
  • 8
  • 40
  • 58
1
vote
1 answer

Passing reference to QPixmap ctor

When I try to pass what appears to be a reference to my QPixmap, I get an error: error: no matching function for call to ‘QGraphicsScene::addItem(QGraphicsPixmapItem (&)(QPixmap))’ The problem is that I don't know where this reference is coming…
zeboidlund
  • 9,731
  • 31
  • 118
  • 180
1
vote
1 answer

Objective-C Blocks, C++ Variables and async code

I'm having an issue while glueing together c++ vars with obj-c async code on iOS. The real problem is located in the async code, I'm using third-party libraries built in C++ that expect object references, e.g.: - (void) processFrame:(cv::Mat…
1
vote
2 answers

subtleties of passing by reference in C

I'm maintaining some C code that was written by the person who had my job last. A situation has come up regarding passing by reference. Here's a shortened, contrived example of what I'm working with: static int b; void SetToTen(int *a){ b =…
Ben
  • 13
  • 2
1
vote
2 answers

Zend Framework: Pass by reference to view helper not working

Here is a simple view helper (notice the pass-by-reference argument): class Zend_View_Helper_MyViewHelper extends Zend_View_Helper_Abstract { public function MyViewHelper(&$array) { unset($array['someExistingKey']); } } This does not work…
fronzee
  • 1,668
  • 2
  • 21
  • 32
1
vote
4 answers

passing struct parameter by reference c++

how can i pass a struct parameter by reference c++, please see below the code. #include #include #include #include using namespace std; struct TEST { char arr[20]; int var; }; void foo(char * arr){ …
Carlitos Overflow
  • 609
  • 3
  • 13
  • 41
1
vote
2 answers

How does a compiler implement pass by value and pass by reference?

I would like to know if you could help me to know the idea behind pass by value and pass by reference that the compiler needs to make, what are the steps involved? I'd be really helpful if you could give me a hand on this since I'm working on a…
1 2 3
99
100