pass-by-reference Questions

1

Solved

Consider this code (godbolt): #include <iostream> template<typename F> void call_by_val(F funct) { std::cout << "call_by_val(): "; funct(); } template<typename ...

9

Solved

I'm a complete Java noob. I know that Java treats all parameters as pass by value and there are several other threads where people explain this. For example, in C++ I can do: void makeAThree(int ...
Christophe asked 25/10, 2011 at 4:5

4

Solved

I'm looking through an API written in C++ and I'm confused as to what the following parameter type means: void*& data Does that mean the user would pass in a reference to a void pointer? If tha...
Wingless asked 20/11, 2010 at 19:55

10

Solved

I would like to call a method which could potentially take on different versions, i.e. the same method for input parameters that are of type: boolean byte short int long The way I would like to...
Reposit asked 7/9, 2010 at 20:9

18

Solved

How do I pass variables by reference in JavaScript? I have three variables that I want to perform several operations to, so I want to put them in a for loop and perform the operations to each one. ...
Loma asked 12/10, 2011 at 18:18

41

Solved

I wrote this class for testing: class PassByReference: def __init__(self): self.variable = 'Original' self.change(self.variable) print(self.variable) def change(self, var): var = 'Changed' ...
Mokas asked 12/6, 2009 at 10:23

6

Solved

A simple question for which I couldn't find the answer here. What I understand is that while passing an argument to a function during call, e.g. void myFunction(type myVariable) { } void main() ...
Delinda asked 19/1, 2014 at 10:10

18

Is it possible to give a default value to a parameter of a function while we are passing the parameter by reference. in C++ For example, when I try to declare a function like: virtual const ULONG...
Pomelo asked 29/6, 2009 at 18:5

35

The primitive types (number, string, etc.) are passed by value. Still, objects are unknown because they can be both passed by value (in which case we consider that a variable holding an object is a...
Monoatomic asked 5/2, 2009 at 21:23

5

Solved

I have a tree of categories of the following structure: [6] => Array ( [id] => 6 [name] => computers [productCount] => 0 [children] => Array ( [91] => Array ( [id] =>...
Douglas asked 1/12, 2010 at 8:59

1

Solved

Consider: #include <iostream> using namespace std; void Change(int arr[3]) { for (int i = 0; i < 3; i++) { arr[i] = 1; } } int Test() { int arr[3] = { 0, 0, 0 }; for (int i =...

1

Upon code review/clang-tidy runs, I came across a function with a signature like this: void appendFoo(const char * fmt, va_list& rVaList); I have never seen this before. Afaik, you can pass va...
Donkey asked 13/2, 2023 at 14:1

13

Solved

I'm having a problem with optional function parameter in C++ What I'm trying to do is to write function with optional parameter which is passed by reference, so that I can use it in two ways (1) an...
Deathwatch asked 12/5, 2010 at 5:49

3

Solved

I have read that reference is just an alias to a variable existing in the symbol table. Consider the following code int main() { int y = 6; int &z = y; int k = 43; test(2,y,5,78); cout &l...
Please asked 14/9, 2016 at 2:37

5

Solved

Code will explain all: class ResultOverlay extends StatefulWidget { final bool _isCorrect; VoidCallback _onTap; ResultOverlay(this._isCorrect, this._onTap); ...... ...... } Its state cla...
Machellemachete asked 31/5, 2018 at 13:42

11

Solved

If I am passing an object to a method, why should I use the ref keyword? Isn't this the default behaviour anyway? For example: class Program { static void Main(string[] args) { TestRef t = new...
Hufford asked 9/10, 2008 at 11:49

3

Solved

I've never used std::get_if, and since its name is different from std::get, I don't see a reason why its argument should be a pointer¹ (whereas std::get has a by-reference parameter). ¹If it was n...
Tracee asked 21/9, 2021 at 14:41

11

Solved

I am hoping that someone can clarify what is happening here for me. I dug around in the integer class for a bit but because integer is overriding the + operator I could not figure out what was goin...
Condominium asked 25/7, 2010 at 20:24

6

Solved

Let's consider an object foo (which may be an int, a double, a custom struct, a class, whatever). My understanding is that passing foo by reference to a function (or just passing a pointer to foo) ...
Incogitant asked 21/10, 2016 at 21:26

3

Solved

I know that the C++/CLI code void foo(Bar^% x); transforms into Void foo(ref Bar x); What is the C++/CLI code that becomes Void foo(out Bar x); ?
Explication asked 18/8, 2010 at 16:19

4

I am using SWIG to access C++ code from Python. How do I elegantly wrap a function that returns values in variables passed by reference like void set(double&a) { a = 42.; } I could not find...
Lunseth asked 12/8, 2010 at 18:6

15

Solved

Let us say we have a function of the form: const SomeObject& SomeScope::ReturnOurObject() { if( ! SomeCondition ) { // return early return ; } return ourObject; } Clearly the code abo...
Fulmis asked 18/11, 2009 at 10:22

7

Solved

If I pass a dataframe to a function and modify it inside the function, is it pass-by-value or pass-by-reference? I run the following code a = pd.DataFrame({'a':[1,2], 'b':[3,4]}) def letgo(...
Ironworker asked 11/8, 2016 at 11:59

6

Solved

I came across some code that used a method like this: QList<Item*> itemList; void addItem(Item* const& item) { itemList.append(item); } Now, I can't see any meaningful difference betw...
Oligocene asked 26/3, 2011 at 0:8

3

Solved

I create a function somewhere and I bind it to this so that I can use the parent block's meaning of this as the value of this within the function. For example: var foo = function() { // some stuf...
Machuca asked 14/4, 2018 at 18:50

© 2022 - 2024 — McMap. All rights reserved.