by-reference

How do I persist a ByRef variable into .net winforms dialog form?

I am creating a "department picker" form that is going to serve as a modal popup form with many of my "primary" forms of a Winforms application. Ideally the user is going to click on an icon next to a text box that will pop up the form, they will select the department they need, and when they click OK, the dialog will close and I will ha...

Using arrays by reference in PHP

Hi, Why is the following code "crashing" in PHP?: $normal_array = array(); $array_of_arrayrefs = array( &$normal_array ); end( $array_of_arrayrefs )["one"] = 1; // choking on this one The expected result is that the final code line appends $normal_array with key "one" having value 1. In the real context of this scenario I use ...

How can I use array-references inside arrays in PHP?

I want to be able to do the following: $normal_array = array(); $array_of_arrayrefs = array( &$normal_array ); // Here I want to access the $normal_array reference **as a reference**, // but that doesn't work obviously. How to do it? end( $array_of_arrayrefs )["one"] = 1; // choking on this one print $normal_array["one"]; // sho...

PHP by-reference parameters and default null

Let's say we have a method signature like public static function explodeDn($dn, array &$keys = null, array &$vals = null, $caseFold = self::ATTR_CASEFOLD_NONE) we can easily call the method by omitting all parameters after $dn: $dn=Zend_Ldap_Dn::explodeDn('CN=Alice Baker,CN=Users,DC=example,DC=com'); We can also call the metho...

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 ListToStdVec( const List<double>& input_list, std::vector<double>& output_vector ) ...

modifying a function parameter (a pointer) from within the application

This is a question based on C code for Win32. In one of my functions I have the following code: void SeparateStuff() { HGLOBAL hMem; IStream* pStream; Status result; unsigned char* pBytes; DWORD size; FILE* fp; if (hMem = GlobalAlloc(GMEM_MOVEABLE, 0)) { if (CreateStreamOnHGlobal(hMem, FALSE, &pStr...

Is there any way to pass an anonymous array as an argument in C++?

Hi all, I'd like to be able to declare an array as a function argument in C++, as shown in the example code below (which doesn't compile). Is there any way to do this (other than declaring the array separately beforehand)? #include <stdio.h> static void PrintArray(int arrayLen, const int * array) { for (int i=0; i<arrayLen; i++) p...

PHP: Use variable name to call static function on Singleton Object

I need to call a static function from an object using the Singleton design, but using a variable as the class name. The best way, $class::getInstance();, is only available in PHP 5.3, and the other way I found, call_user_func(array($class, 'getInstance'));, results in the maximum execution time being breached. Does anyone know why this ...

C# - Does foreach() iterate by reference?

Consider this: List<MyClass> obj_list = get_the_list(); foreach( MyClass obj in obj_list ) { obj.property = 42; } Is 'obj' a reference to the corresponding object within the list so that when I change the property the change will persist in the object instance once constructed somewhere? ...

PHP recursive function + array by reference = headache

I have an interesting problem. The basis of the problem is that my last iteration of an array reference doesn't seem to "stick," if you will. A little context: I've devised a very simple data structure for page heirarchy that looks like this: ,1,2,3>,4>,5,6,7<<,8 Translation: forget about the annoying leading commas. Pages 1, 2, 3, & 8...

Interfaces with structs, by reference using Generics

Sorry guys! i am so into the code! that i forgot to put the compiler errors. Here is a new version of the code simplified! And this are the errors: Error 1 The best overloaded method match for 'IWeird.DataBase.ModifyData(ref IWeird.IDataTable)' has some invalid arguments Error 2 Argument '1': cannot convert from 'ref IWeird.Period...

Is it a bad practice to pass structs by reference?

I usually save serialized structs to my database, so I pass them by reference a lot! Is that a bad practice? ...

Please help with C++ syntax for const accessor by reference.

Right now my implementation returns the thing by value. The member m_MyObj itself is not const - it's value changes depending on what the user selects with a Combo Box. I am no C++ guru, but I want to do this right. If I simply stick a & in front of GetChosenSourceSystem in both decl. and impl., I get one sort of compiler error. If I do ...