pass-by-reference

Reference parameter being copied in variadic template

回眸只為那壹抹淺笑 提交于 2019-12-13 18:30:46
问题 I have an Event class that stores a set of tuples of weak_ptr (the observer) to a function that gets executed when the event is "fired". The function type is: void(int &) in the example. That is to say, I want to fire the event passing a reference to a value, to have the observer change that value and to verify that the value was changed back in the observed object. The event implementation is variadic by the way, which may complicate the issue (at least the code). At the moment this is

Returning result via Output-parameter, c++ coding standard [duplicate]

﹥>﹥吖頭↗ 提交于 2019-12-13 15:21:08
问题 This question already has answers here : best practice for parameters? (5 answers) Closed 6 years ago . I have a member function in my class like this: int MyClass::m_Func(int& val); in which, I do some operation and put the result in val . And depending upon the result of the operation, I returned different values from the function. Like, if it is successful, I return 0 or other values if any error occurs. One of my friend told me that it is not a good practice to pass a reference of a

Is using pointers in C++ always bad?

会有一股神秘感。 提交于 2019-12-13 13:15:15
问题 I was told to avoid using pointers in C++. It seems that I can't avoid them however in the code i'm trying to write, or perhaps i'm missing out on other great C++ features. I wish to create a class (class1) which contains another class (class2) as a data member. I then want class2 to know about class1 and be able to communicate with it. I could have a reference to class1 as a member in class2 but that then means I need to provide a reference to class1 as a parameter in the constructor of

pass by reference c++

故事扮演 提交于 2019-12-13 12:25:35
问题 My teacher in c++ told me that call by reference should only be used if I'm not going to change anything on the arrays inside the function. I have some really big vectors that I'm passing around in my program. All the vectors will be modified inside the functions. My matrices are of sizes about [256*256][256][50] ... Is there some particular reason not to use call-by reference here? AFAIK call by reference should be way faster and consume less memory? 回答1: My teacher in c++ told me that call

Passing reference to activity to utility class android

六眼飞鱼酱① 提交于 2019-12-13 11:36:28
问题 I realise this question has been asked many times, but I am still unable to completely understand this concept. In my application, I am using a static utility class to keep common methods (like showing error dialogs) Here is how my static class looks like: public class GlobalMethods { //To show error messages public static final void showSimpleAlertDialog(final Activity activity, String message, final boolean shouldFinishActivity) { if (!activity.isFinishing()) { AlertDialog.Builder builder =

Pass a data structure to a function and access the fields of the data structure like an array in C#

﹥>﹥吖頭↗ 提交于 2019-12-13 10:50:17
问题 I have a set of fields of different types, I must group them into any data structure. Then I have to pass it to a function and modify the fields the data structure with indexes, like array. How would I do this? Thanks to everyone. mytype{ int a; ushort b; string c; } And I would like to pass this data structure that groups all these fields, it can be class or struct. And Pass this to a function and would like to modify the fields of that instance with indexes, like this: void function(ref

Why are all the values in my list the same? [closed]

∥☆過路亽.° 提交于 2019-12-13 10:37:22
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 6 years ago . In java, I'm trying to populate a list with a bunch of different objects. But what is happening is, each time I add another object to the list, all the objects in the list get turned into the same thing. The code in question: private static ArrayList<Card> deck = new ArrayList<Card>(); private static void

Differences between passing by reference and passing by address

Deadly 提交于 2019-12-13 10:14:25
问题 int func(int a, int& b){ if (a < 3){ return b; } else{ b++; return func( a/10, b); } } I think b here is passed by pointer which is the same as passing by reference. What is passing by address, how it differs from passing by reference? Is there any variable in above is passed by address? Also, why func(40, 0) gave me an error as output? 回答1: Let me try to make you understand in easy way. When you declared any variable in your c++ program then compiler create an entry in the symbol table for

Deprecated: Call-time pass-by-reference has been deprecated in

帅比萌擦擦* 提交于 2019-12-13 09:45:41
问题 what is the best substitute for settype() in php 5.3.5 due to this error/warnings Deprecated: Call-time pass-by-reference has been deprecated in C:\xampp\htdocs\MyWebInterface\includes\payroll_cutoff.inc.php on line 217 回答1: settype() hasn't been deprecated. Passing by reference at call time has been deprecated. You probably just want to remove the ampersand from in front of the first parameter to your settype() call. That would be easier to tell for sure if you actually posted your code...

If perl is call-by-reference why does this happen?

只谈情不闲聊 提交于 2019-12-13 07:58:56
问题 I've read that perl uses call-by-reference when executing subrutines. I made a simple piece of code to check this property, but it behaves like if perl was call-by-value: $x=50; $y=70; sub interchange { ($x1, $y1) = @_; $z1 = $x1; $x1 = $y1; $y1 = $z1; print "x1:$x1 y1:$y1\n"; } &interchange ($x, $y); print "x:$x y:$y\n"; This produces the following output: $ perl example.pl x1:70 y1:50 x:50 y:70 If arguments were treated in a call-by-reference way, shouldn't x be equal to x1 and y equal to