pass-by-reference

Using references in PHP.

I ask this question because i learned that in programming and designing, you must have a good reason for decisions. I am php learner and i am at a crossroad here, i am using simple incrementation to try to get what im asking across. I am certainly not here to start a debate about the pros/cons of referencing, but when it comes to php, ...

What is the best way to organize Java code since you can't pass by reference?

I'm learning how to code in Java after after coming from C. In C I always separated everything into individual functions to make the code easier to follow and edit. I was trying to do this in java but now since I realized that you can't use pointers, I am a bit confused as to what the best way to do this is. So for example I want to hav...

C# Passing objects and list of objects by reference

I have a delegate that modifies an object. I pass an object to the delegate from a calling method, however the calling method does not pickup these changes. The same code works if I pass a List as the object. I thought all objects were passed by reference so any modifications would be reflected in the calling method? I can modify my cod...

Pass an argument by reference in C++/CLI so re-assignment affects the caller

Probably this is not a difficult question, but I am always a little bit confused on how to treat String type as an argument in Visual C++. I have the following to functions: void function_1(String ^str_1) { str_1 = gcnew String("Test"); } void function_2() { String ^str_2 = nullptr; function_1(str_2); } After calling function_1...

Modify in place the elements of a vector

The following doesn't work as desired (print 2) because, I guess, the nodes are passed by value even though the vector is passed by reference. How could I fix it? #include <iostream> using std::cout; using std::endl; #include <vector> using std::vector; class Node{ public: int value; Node(int); void createC...

Using the value of a field as column name in a query

I'm trying to figure out a way to only grab the specific field that pertains to an operation step a unit is in. I have one table with units and their operation step, then I have another table that has a column for each step. I want to pull only the column that relates to that unit's current step. Here is my attempt but I can't seem to...

Why is calling a function (such as strlen, count etc) on a referenced value so slow?

I've just found something very strange in PHP. If I pass in a variable to a function by reference, and then call a function on it, it's incredibly slow. If you loop over the inner function call and the variable is large it can be many orders of magnitude slower than if the variable is passed by value. Example: <?php function TestCoun...

c++ rvalue passed to a const reference

I'm trying to understand exact C++ (pre C++0x) behavior with regards to references and rvalues. Is the following valid? void someFunc ( const MyType & val ) { //do a lot of stuff doSthWithValue ( val); } MyType creatorFunc ( ) { return MyType ( "some initialization value" ); } int main () { someFunc ( creatorFun...

Can I pass subset of an array to function in VB.Net?

I have a simple VB.Net Form that acts as an interface to a control library with a public API. One of the API calls takes an Array of UIntegers ByRef: Public Function Get_Values(source_id As Byte, first_value_address As Byte, number_of_values As Byte, ByRef valuesOut As UInteger()) As Integer After the call, valuesOut will hold a list...

Assigning value passed by reference to a member variable (in C++)

I am trying to wrap my head about scope in C++. Please consider the following: class C { int i_; public: C() { i_ = 0;} C(int i) { i_ = i; } C(const C &c) { i_ = c.i_; cout << "C is being copied: " << i_ << endl; } int getI() { return i_; } ~C() {cout << "dstr: " << i_ << endl;} }; class D { ...

Confusion in C++

I'm very new to C++ and I'm currently learning it. I got a few questions.. What is the differences between void DoSomething(const Foo& foo) and void DoSomething(Foo foo)? If we don't specify & then the instance of Foo will be passed by value ( not reference ). It will be the same as having const + & in argument except no checking at co...

Is it possible to pass a variable stored in an array by reference in PHP?

If I want myFunction to take $myVariable and assign to it an instance of SomeClass, I know I can do this: class SomeClass { } function myFunction(&$myVariable) { $myVariable = new SomeClass(); } myFunction($myVariable); var_dump($myVariable); However, I would like to be able to have myFunction operate like this: class SomeClas...

PHP: check if object/array is a reference

Sorry to ask, its late and I can't figure a way to do it... anyone can help? $users = array( array( "name" => "John", "age" => "20" ), array( "name" => "Betty", "age" => "22" ) ); $room = array( "furniture" => array("table","bed","chair"), "objects" => array("tv","radio","bo...

In C++ how can you create class instance w call to either a struct or nothing?

I'm creating a Class. This class stores user preferences in a Struct. When creating an instance of the class, I want the client to have the option of creating an instance with no preferences passed in or with a preferences struct passed in. I can do this with pointers, but I wanted to know how I could do it by passing the preferences...

array holding reference to extinct object

I thought that if a C# array held reference types it would simply hold references to each of the objects, however the code below tells me otherwise. It appears as if the array is holding a reference to an object of which I thought was set to be garbage collected. I feel like i'm missing something fundamental here. Can anyone tell me w...

Does php5 function parameters pass as ponter or as copies?

Hi, Does php function parameters pass as ponter to object or as copy of object? Its very clear in C++ but in php5 I don't know. Example: <?php $dom=new MyDocumentHTMLDom(); myFun($dom); ?> parameter $dom pass as pointer or as copy? Thanks ...

Integral promotion when passing and returning argument by reference?

Hi! I'm reading something about overload resolution and I found something that bothers me...In the following code: int const& MaxValue(int const& a, int const& b) { return a > b ? a : b; } void SomeFunction() { short aShort1 = 3; short aShort2 = 1; int const & r2 = MaxValue(aShort1, aShort2); // integral promotion ...

ASP.NET web services using reference parameters in webmethod

I have an issue when I try to retrieve info through a webmethod. I am using a proxy to call a web service, in that proxy I have an operation which returns data using 'out' parameters. The server executes the operation succesfully, giving back the parameters properly instanced (I also have checked the soap return message using a traffic...

Assign a reference of an integer in a class

Is it possible to pass an integer as reference at class initialization and safe the reference? class Foo { private int _refVal; public Foo(ref int val) { _refval = val; // saves the value, not the reference } } I could use pointers, but then I need an unsafe context. ...

Automatic Evaluation Strategy Selection in C++

Consider the following function template: template<typename T> void Foo(T) { // ... } Pass-by-value semantics make sense if T happens to be an integral type, or at least a type that's cheap to copy. Using pass-by-[const]-reference semantics, on the other hand, makes more sense if T happens to be an expensive type to copy. Let's ass...