pass-by-reference

java vs C++ pass by reference

Hi, I am confused in the following: In C++ we can pass a parameter to a function by reference (having declared it as a pointer or reference variable) and if we modify it inside the function, the changes are reflected to the caller when the function returns. This is not happening in java and I am not sure I understand why. E.g. this is a...

Passing a object by reference in c++

This is a noobie question, but I'm not sure how to pass by reference in C++. I have the following class which sets up a Node and a few functions. class Node { public: Node *next; int data; Node(int dat) { next = NULL; data = dat; } Node* getNext() { return next; } void setNext(Node *n) {...

Keeping track of a class's references in PHP

I used the instructions in this post: http://stackoverflow.com/questions/475569/get-all-instances-of-a-class-in-php to keep all instances of a class in an array. But when I change an object inside of the array, it doesn't change the "original". class Pane { protected $data; public $name; public static $instances = array(); pu...

Pass data between objects in python

I'm new to python and I'm not sure how to pass data between objects. Below is a tabbed program using python and wxwidgets. How would I be able to access the maintxt instance from the GetText method since their in different classes? Thanks. ........ #!/usr/bin/env python import wx class PageText(wx.Panel): def __init__(self, pare...

Template parameters in C++

Suppose I have arbitrary template method, which could receive parameters by value and by const reference (obviously, for trivial types and for objects accordingly). How is this situation handled when writing template function prototypes? I could make something like: template <typename T> void Foo(T value) { // Do something. } temp...

when i need pass by pointer (and not by reference)

Can you give me an example when I can't pass argument by reference and I need to use pointer. I've found an example, but I'm not sure. Suppose you have a class D derived from the base class B. You need pointer if you want do so: void function(B* b){...} int main{ D* d; function(d); } ...

c++ references array

Hello, I wounder how i can make this code work? #include <iostream> using namespace std; void writeTable(int (&tab)[],int x){ for(int i=0;i<x;i++){ cout << "Enter value " << i+1 <<endl; cin >> tab[i] ; } } int main(void){ int howMany; cout << "How many elemets" << endl; cin >> howMany; int tab...

Is there simple PHP code to distinguish "Passing the object as reference" vs "Passing the object reference as value"?

This is related to question: http://stackoverflow.com/questions/3957584/how-does-operator-work-in-php-function/3957669#3957669 Is there simple code to show the difference between passing the object as reference vs passing the object's reference as value? ...

In PHP, when foo = new Foo(), technically speaking, is foo an object, or is foo a reference?

Update: in http://php.net/manual/en/language.oop5.references.php it says: One of the key-points of PHP5 OOP that is often mentioned is that "objects are passed by references by default". This is not completely true. Why is that? The following is a reason which I don't know is completely true or not: I think loosely ...

PHP Call-time pass-by-reference unavoidable?

Given the following interface: interface ISoapInterface { public static function registerSoapTypes( &$wsdl ); public static function registerSoapOperations( &$server ); } And the following code: $soapProvider = array( "FilePool", "UserList" ); foreach( $soapProvider as $provider ) { call_user_func( array( $provider, "registerSo...

passing enums by ref in java

How can i pass enum parameter by reference in java? Any solution? ...

Passing/modifying multidimensional array to function in C

I haven't used C in 5-6 years, and feel that this is probably a really obvious answer. I thought that arrays were passed by reference automatically in C, so my code below should modify the values of the array created in main() within the change function. It changes the values of the local variable within the change function, but this is...

Javascript: Re-assigning a function with another function

Let's say I have these two functions: function fnChanger(fn) { fn = function() { sys.print('Changed!'); } } function foo() { sys.print('Unchanged'); } Now, if I call foo(), I see Unchanged, as expected. However, if I call fnChanger first, I still see Unchanged: fnChanger(foo); foo(); //Unchanged Now, I assume this is becaus...

Why do we pass by reference when we have a choice to make the variable external?

Suppose we have an array say: int arr[1000]; and I have a function that works on that array say: void Func(void); Why would there ever be a need to pass by reference (by changing the void), when I can have arr[1000] as an external variable outside main()? What is the difference?Is there any difference? Why do people prefer passin...

Java recursion: pass by reference

I realize this is a hotly debated, controversial topic for Java programmers, but I believe my problem is somewhat unique. My algorithm REQUIRES pass by reference. I am doing a clockwise/counterclockwise pre-order traversal of a general tree (i.e. n-children) to assign virtual (x,y) coordinates. This simply means I count (and tag) the nod...