pass-by-reference

Confusion between passing and modifying char pointers in C (reference vs. value)

Hi, I was wondering if you could help me out with a C string problem I don't quite understand. I have a function to which I send 3 char pointers. Within this function, the char pointers are shifted and modified correctly. However, when I return to the main function from which they are called, said functions are not changed. Am I passing ...

Java: Pass by reference / ListIterator.add()

Java doesn't pass variables by reference. In that case, how do data structures like ListIterator make changes to their corresponding list? Here is an example iterator I am writing: public class OdpIterator<E> implements ListIterator<E> { private OdpList<E> list; private int cursor; public OdpIterator(OdpList<E> list) { ...

some kind off variable problem within php class

Hello, I have this in my class When the second function is called php errors with wrong datatype and only variables can be past by reference. I don't know what they mean by that This code comes from php.net If the same code is outside the class it executes fine What am I doing wrong here, if I am working within a class? $extensiesA...

Assign a C++ out reference to something that was destroyed?

Hello, So I'm looking through some code, and I see this: class whatever { public: void SomeFunc(SomeClass& outVal) { outVal = m_q.front(); m_q.pop(); } private: std::queue<SomeClass> m_q; }; This doesn't seem like outVal would be a valid reference any more... However, it appears to work. I've see...

C# and storing reference to method parameter

For a little background information, I've got an application that's running in a loop, and over ever tick it calls a method Tick. There's a bunch of classes that extend a base class and all have their own tick methods, and get added to a dependency chain so that say when class A gets called and it's chain has instances of B and C in it,...

Trimming string variables by reference in PHP5

I saw another post suggesting using this statement to trim string variables contained in the array: $_POST=array_map('trim', $_POST); However, if in the first place, the strings are not contained in an array, I would like to have a trim function that can be used like this: $a=' aaa '; $b=' bbb '; $c=' ccc '; trimAll($a,$b,$c); //a...

Passing By ref and out

So if I am iterating using a foreach loop and I have a function inside that takes an argument of the object iterated from list, and lets say i set its value to be different. Why don't I have to use out or ref ? I thought it was only passed by value if it you didn't use out or ref.... I know that a ref you must have initialized the variab...

Teaching References in C#

In a couple of weeks, I'll be teaching a class of first-year engineers the salient points of references in C# as part of their first-year programming course. Most of them have never programmed before, and had enough trouble learning objects, so teaching references is going to be an uphill battle. I plan to have lots of examples availab...

Pretending .NET strings are value type

In .NET, strings are immutable and are reference type variables. This often comes as a surprise to newer .NET developers who may mistake them for value type objects due to their behavior. However, other than the practice of using StringBuilder for long concatenation esp. in loops, is there any reason in practice that one needs to know th...

How to get the value of a value passed by reference in C++

I have a function with the following declaration: void cleanValid(int valid[][4], int &size, int index); In implementation of this function I need to set another counter equal to the integer size passed by reference. I tried doing something like: int count; count = size; If I'm not mistaken, when I change the value of count it will...

Using REF & OUT keywords with Passing by Reference & Passing by Value in C#

Here is what I understand so far: PASS BY VALUE Passing by value means a copy of an argument is passed. Changes to that copy do not change the original. PASS BY REFERENCE Passing by reference means a reference to the original is passed. changes to the reference affect the original. REF Keyword REF tells the compiler that the objec...

Can you pass by reference in Java?

Hi. Sorry if this sounds like a newbie question, but the other day a Java developer mentioned about passing a paramter by reference (by which it was ment just pass a Reference object) From a C# perspective I can pass a reference type by value or by reference, this is also true to value types I have written a noddie console application...

DataGridView: Pass by Value or Reference?

I think of DataGridView's as being memory hogs. Is it better to pass by value a datagridview or by reference? Should it even be passed at all? ...

Best way to return early from a function returning a reference

Let us say we have a function of the form: const SomeObject& SomeScope::ReturnOurObject() { if( ! SomeCondition ) { // return early return ; } return ourObject; } Clearly the code above has an issue, if the condition fails then we have a problem as to how to return from this function. The crux of my ...

Is is better to do const pass by references over non-const pass by references?

I came across this. http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml?showone=Reference_Arguments#Reference_Arguments According to the style guide, only const references are allowed as parameters. (That's what I understood) Although, I don't seem to like that approach. Comments? ...

Using recursively returned reference to node in tree does not allow changes to the node itself

My data structures class is working with trees. We are implementing a 3-ary tree, containing 2 values with a reference to a left, middle, and right node (left subtree is less than value 1, middle subtree is between value 1 and value 2, right subtree is greater than value 2). An interface has been provided for the Tree class, and the fin...

C# pass int and string by reference to C++ ActiveX Control: type mismatch

I have a problem passing by reference int or string variables to C++ ActiveX Control. Also I pass these variables by reference to C++ DLL and everything works fine. C++ DLL: __declspec (dllexport) void Execute (LPCTSTR cmd, int& resultCode, LPCTSTR& message, long& receiptNumber) { message = _T("ReplyProblem"); resultCode = 100...

Problem with returning arguments that are const references

I know why the following does not work correclty, so I am not asking why. But I am feeling bad about it is that it seems to me that it is a very big programming hindrance. #include <iostream> #include <string> using namespace std; string ss("hello"); const string& fun(const string& s) { return s; } int main(){ const s...

How to copy the value of a reference in javascript?

Some time ago I posted a question about what questions should a good javascript coder be able to answer. Meder pointed out the following question: The following code makes clicks on any "a" element to alert(-1) due to the fact that "i" is hold in the onclick function as a reference and not as a value: <a href="#">text</a><br><a href="...

Pass by value or reference, to a C++ constructor that needs to store a copy?

Should a C++ (implicit or explicit) value constructor accept its parameter(s) by value or reference-to-const, when it needs to store a copy of the argument(s) in its object either way? Here is the shortest example I can think of: struct foo { bar _b; foo(bar [const&] b) // pass by value or reference-to-const? : _b(b) { ...