pass-by-reference

PHP. Pass variable by reference vs string. How to works with these two different arguments?

梦想的初衷 提交于 2020-01-16 14:29:11
问题 I'm writing my own debug functions and I need some help to fix the code below. I'm trying to print a variable and its name, the file where the variable and the function was declared and the line of the function call. The first part I did, the variable, the variable name, the file and the line is printed correctly. At the code, a($variable) works good. The problem is I'd like this function accepts a string too, out of a variable. But PHP returns with a fatal error ( PHP Fatal error: Only

Temporary non-const istream reference in constructor (C++)

别等时光非礼了梦想. 提交于 2020-01-15 11:03:01
问题 It seems that a constructor that takes a non-const reference to an istream cannot be constructed with a temporary value in C++. #include <iostream> #include <sstream> using namespace std; class Bar { public: explicit Bar(std::istream& is) {} }; int main() { istringstream stream1("bar1"); Bar bar1(stream1); // OK on all platforms // compile error on linux, Mac gcc; OK on Windows MSVC Bar bar2(istringstream("bar2")); return 0; } This compiles fine with MSVC, but not with gcc. Using gcc I get a

Temporary non-const istream reference in constructor (C++)

耗尽温柔 提交于 2020-01-15 11:02:09
问题 It seems that a constructor that takes a non-const reference to an istream cannot be constructed with a temporary value in C++. #include <iostream> #include <sstream> using namespace std; class Bar { public: explicit Bar(std::istream& is) {} }; int main() { istringstream stream1("bar1"); Bar bar1(stream1); // OK on all platforms // compile error on linux, Mac gcc; OK on Windows MSVC Bar bar2(istringstream("bar2")); return 0; } This compiles fine with MSVC, but not with gcc. Using gcc I get a

Why would I pass function parameters by value in C?

江枫思渺然 提交于 2020-01-14 14:22:47
问题 I am dusting off my C skills working on some C libraries of mine. After having put together a first working implementation I am now going over the code to make it more efficient. Currently I am on the topic of passing function parameters by reference or value. My question is, why would I ever pass any function parameter by value in C? The code might look cleaner, but wouldn't it always be less efficient than passing by reference? 回答1: In C, all arguments are passed by value. A true pass by

Pointers passed by reference updated with every loop iteration: (Sanity check - Part 2)

元气小坏坏 提交于 2020-01-13 21:05:13
问题 I am trying to grasp come concepts related to pointers and references. In the code snippet below, I call function shifting() several times from a for loop while iterating a linked list. With each iteration, int *ptr and int count are changed and passed to the function shifting(). Also, some other pointers and integer variables are passed by reference . Doubts: can I assign pointer references like shown in shifting() function? Same question for integer val references. What is going on in the

Passing an anonymous variable by reference

可紊 提交于 2020-01-12 08:00:13
问题 Standard C++ types such as int or char have ctors, so you can have expressions like: int a = int(67); // create anonymous variable and assing it to variable a int b(13); // initialize variable b int(77); // create anonymous variable User defined types (structures or classes) are able to do the same: struct STRUCT { STRUCT(int a){} }; STRUCT c = STRUCT(67); STRUCT d(13); STRUCT(77); The question is: why can we pass by a reference anonymous structure or class instances, but can not pass

Do I need to use the ampersand in PHP 5.5.X and above anymore?

旧巷老猫 提交于 2020-01-12 07:23:07
问题 I'm getting mixed signals all over the place. Do I use the ampersand to pass variables by reference or not? The following link seems to tell me that it is deprecated and no longer necessary: http://gtk.php.net/manual/en/html/tutorials/tutorials.changes.references.html But threads like these make me wonder: Call-time pass-by-reference deprecated? PHP and ampersand Let me phrase my question as an example. If I make a function, using PHP 5.5.5: function recurring_mailer_form($form, $form_state)

Is Ruby pass-by-value or pass-by-reference? [duplicate]

岁酱吖の 提交于 2020-01-12 05:57:06
问题 This question already has answers here : Is Ruby pass by reference or by value? (12 answers) Closed 5 years ago . I am basically a java developer. I am working in ruby for about an year. Unlike java, Ruby is a pure object oriented programming language. Here comes a doubt. Is it pass-by-value or pass-by-reference? Java works as pass-by-value: "When passing primitives, I see that the value is duplicated and passed to the method. But incase of Objects, the reference is duplicated and passed to

What does the [REFERENCE] tag do in an argument declaration?

China☆狼群 提交于 2020-01-11 11:42:49
问题 I am writing an custom callback function in Fortran for a piece of software (example here) that includes the following argument declaration SUBROUTINE CONTACT_FORCE(TIME,UPAR,NPAR,PEN,RVEL,JFLAG,IFLAG,RESULT) !DEC$ ATTRIBUTES DLLEXPORT,C::CONTACT_FORCE ... DOUBLE PRECISION RESULT[REFERENCE](6) !Compiles ok Which compiles fine with Compaq Visual Fortran 6. So my question is what does the [REFERENCE] tag do? I thought that Fortran passes everything by reference (and not by value). Of course

PHP Call-time pass-by-reference unavoidable?

[亡魂溺海] 提交于 2020-01-11 09:59:15
问题 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, "registerSoapTypes" ), &$server->wsdl ); call_user_func( array( $provider, "registerSoapOperations" ), &$server ); } FilePool and UserList both implement ISoapInterface . PHP will