pass-by-reference

Second order functions in GLSL?

拈花ヽ惹草 提交于 2020-02-21 12:33:43
问题 I'm looking for a way to use a function as an argument to another function in GLSL. In regular C, it can be simulated by passing a function pointer as a function argument. It also seems that other languages (like HLSL) now provide ways to deal with high-level constructs like higher-order functions, or can simulate them with clever use of HLSL structures. unfortunately I'm stuck with GLSL for now, and I can't find any way to simulate higher-order functions. Is it really impossible in current

c++ pass a map by reference into function

旧巷老猫 提交于 2020-02-18 08:22:11
问题 How can I pass a map by reference into a function? Visual Studio 2010 is giving me an unresolved externals error. Currently, I have the following simplified code: void function1(){ map<int, int> * my_map = new map<int, int>(); function2(*my_map); } void function2(map<int, int> &temp_map){ //do stuff with the map } There's a few answers to similar questions here, but they make use of typedef and adding std:: to the beginning of the definition but I'm really not sure why. int ComputerPlayer:

c++ pass a map by reference into function

北慕城南 提交于 2020-02-18 08:20:47
问题 How can I pass a map by reference into a function? Visual Studio 2010 is giving me an unresolved externals error. Currently, I have the following simplified code: void function1(){ map<int, int> * my_map = new map<int, int>(); function2(*my_map); } void function2(map<int, int> &temp_map){ //do stuff with the map } There's a few answers to similar questions here, but they make use of typedef and adding std:: to the beginning of the definition but I'm really not sure why. int ComputerPlayer:

Update global variable in C via reference by parameter

自古美人都是妖i 提交于 2020-01-30 11:22:05
问题 short int PC = 0; int main() { foo(&PC) ; } void foo(short int PC) { PC++; } How do I successfully update the global variable of PC? Note : PC must be passed as a parameter and the global variable needs to be modified via the parameter. As you can tell I am new to C and am trying to understand the difference between * and & . Any help would be much appreciated. 回答1: You just need to take the argument as a pointer: short int PC = 0; void foo(short int *pc) { (*pc)++; } int main() { foo(&PC) ;

How does reference to pointer exactly work in C++, and when do we need them (in the case of linked list)

不问归期 提交于 2020-01-30 11:00:07
问题 I know that pointers hold the address of a variable. And references point to the same address in the symbol table (that is, the same address of the variable, that they are assigned to). My question is, how do reference to pointers exactly work. And when do we need them, as opposed to using pointer alone (and not using reference to pointer). It will be helpful if you could explain me the use of reference to pointer, with respect to a singly linked list. I have the following code that deletes

C# is there a difference between passing a struct reference and a class reference to a method in terms of speed?

房东的猫 提交于 2020-01-25 09:23:07
问题 As seen here, structs are passed by copy and classes by reference. But why is passing a struct by reference using the ref keyword still slower than passing a reference to a class ? I got different speeds for my program by replacing the struct keywords with class . All of the variables were already passed with the ref keyword. By changing keywords, I got 20% speed increase in my tests. Shoudn't the speed remain the same since I was already passing by reference ? What am I not understanding ?

x86 Assembly Passing Parameters by Reference

别说谁变了你拦得住时间么 提交于 2020-01-24 20:34:11
问题 Below is my code for assembly language. I can pass by a stack parameter value using "push [edi]" but I cannot seem to pass by reference using "push OFFSET [edi]". What's the correct syntax to pass something by reference in this case? sortList PROC ;Parameter memory addresses: ;numbers @ [ebp+8] ;list @ [ebp+12] ;Used to access stack parameters push ebp mov ebp, esp ;Sets up the array mov edi, [ebp+12] ;Puts in the address of the list array mov ecx, [ebp+8] ;Sets up the loop counter for the

Issue with cloning and pass-by-reference

懵懂的女人 提交于 2020-01-23 05:07:26
问题 So for the past few days I have been tearing my hair out trying to get a class to clone properly. The problem is that cloning doesn't remove/redo any of the pass-by-reference. The result is, that the main data object is still passed as a reference, thus completely negating the effect of the clone. Here's a simplified version of the problem: class my_class { private $data; public $var1; public $var2; public $var3; public function __construct() { $this->data = new stdClass; $this->data->var1 =

Visual C++ 10.0 bug in std::reference_wrapper?

て烟熏妆下的殇ゞ 提交于 2020-01-21 06:20:07
问题 Code: #include <functional> struct Foo { virtual void mf() = 0; }; struct Bar: Foo { virtual void mf() {} }; int main() { Bar o; std::reference_wrapper<Foo const> wrapper( o ); } Result with MinGW g++ 4.6.1: [d:\dev\test] > g++ foo.cpp -std=c++0x [d:\dev\test] > _ Result with Visual C++ 10.0: [d:\dev\test] > cl foo.cpp foo.cpp C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\xxcallwrap(8) : error C2259: 'Foo' : cannot instantiate abstract class due to following members: 'void

Can we overload a function based on only whether a parameter is a value or a reference?

时光怂恿深爱的人放手 提交于 2020-01-21 04:45:42
问题 I got the answer NO! Because passing by value and passing by reference looks identical to the caller. However, the code below compiles right class A { public: void f(int i) {} void f(int& i) {} }; But when I try to use it, there is compile error. int main () { A a; int i = 9; int& j = i; a.f(1); a.f(i); a.f(j); return 0; } Why does not the compiler disable it even without knowing it is going to be used? 回答1: Yes, they can be overloaded based on reference or not. That is why it's perfectly