parameter-passing

Passing condition as parameter

拟墨画扇 提交于 2019-12-04 08:26:12
First of all to explain what I'm trying to do: void Foo(int &num, bool condition); Foo(x, x > 3); This code basically would evaluate the bool of the condition before calling the function and then pass pure true or false. I'm looking for a way to make it pass the condition itself, so I could do something like this: void Foo(int &num, bool condition) { while(!condition) { num = std::rand(); } } I know there could be a workaround by passing a string containing the condition and parsing the latter, and I'm working on it right now, but I find it rather inefficient way. The accepted answer will be

Does inout/var parameter make any difference with reference type?

我只是一个虾纸丫 提交于 2019-12-04 08:15:32
I know what inout does for value types . With objects or any other reference type , is there a purpose for that keyword in that case, instead of using var ? Code example: private class MyClass { private var testInt = 1 } private func testParameterObject(var testClass: MyClass) { testClass.testInt++ } private var testClass: MyClass = MyClass() testParameterObject(testClass) testClass.testInt // output ~> 2 private func testInoutParameterObject(inout testClass: MyClass) { testClass.testInt++ } testClass.testInt = 1 testInoutParameterObject(&testClass) // what happens here? testClass.testInt //

Swapping pointer in C [duplicate]

泪湿孤枕 提交于 2019-12-04 06:42:43
问题 This question already has answers here : Swapping objects using pointers (10 answers) Closed 3 years ago . # include <stdio.h> void mystery (int *ptra, int *ptrb) { int *temp; temp = ptrb; ptrb =ptra; ptra = temp; } int main () { int a = 2016, b=0, c= 4, d = 42; mystery (&a, &b); if (a < c) mystery (&c, &a); mystery (&a, &d); print f("%d\n", a); } My attempt : a and d are not swapped as the function mystery() doesn’t change values, but pointers which are local to the function. Can you explain

Send speech recognition args.Result as parameter in UWP desktop-bridge package

拜拜、爱过 提交于 2019-12-04 06:16:12
I'm trying to figure out, if it is possible send using Windows.Media.SpeechRecognition; args.Result.Text as parameter from UWP to Console application. For example by following scenario I'm sending TextToSpeech(args.Result.Text); with args.Result.Text; value, where using Windows.Media.SpeechSynthesis; text-to-speech pronounces the recognition result each time when args.Result.Text; appears. textBlock2.Text = args.Result.Text; also displays result: private async void ContinuousRecognitionSession_ResultGenerated( SpeechContinuousRecognitionSession sender,

understand passing parameters by reference with dynamic allocation

泪湿孤枕 提交于 2019-12-04 05:27:01
问题 I'm trying understand how to pass a parameter by reference in C language. So I wrote this code to test the behavior of parameters passing: #include <stdio.h> #include <stdlib.h> void alocar(int* n){ n = (int*) malloc( sizeof(int)); if( n == NULL ) exit(-1); *n = 12; printf("%d.\n", *n); } int main() { int* n; alocar( n ); printf("%d.\n", *n); return 0; } Here is printed: 12. 0. Example 2: #include <stdio.h> #include <stdlib.h> void alocar(int* n){ *n = 12; printf("%d.\n", *n); } int main() {

Passing scalars and array elements to a procedure expecting an array

两盒软妹~` 提交于 2019-12-04 04:57:14
问题 I have some legacy Fortran 77 code which I'm trying to at least compile without warnings (without disabling warnings). There are subroutine calls that pass a scalar where subroutine expects an array, since the scalar is used as a size-1 array, this causes no problems. But with the Intel compiler, if I enable interface warnings I get this error : error #8284: If the actual argument is scalar, the dummy argument shall be scalar unless the actual argument is of type character or is an element of

Please Explain this Java Array Reference Parameter Passing Behavior

回眸只為那壹抹淺笑 提交于 2019-12-04 04:37:14
问题 public class TestArray { public static void main(String[] args) { int[] ar = {1,2,3,4,5,6,7,8,9}; shiftRight(ar); for (int i = 0; i < ar.length; i++) { System.out.print(ar[i]); } // prints: 912345678 -- good System.out.println(); reverseArray(ar); for (int i = 0; i < ar.length; i++) { System.out.println(ar[i]); } // prints: 91234567 -- I don't understand System.out.println(); } public static void shiftRight(int[] ar) { int temp = ar[ar.length - 1]; for (int i = ar.length - 1; i > 0; i--) { ar

How do I “connect” a table view to a view controller

北城余情 提交于 2019-12-04 04:24:38
Alright, I know this is a vague conceptual question, but I really need help here. Thanks in advance if you decide to take the time to read this. I would never even consider writing this much except this is such a great forum with so many helpful people I thought this would be the best place to ask. This is all related to the question here (you don't have to look at it - I explain everything below): Pass parameter when initializing table I've been working for days on the same problem, but I'm realizing there must be something big I'm missing. I've googled and googled and I even bought (and

Passing variable values from another method

吃可爱长大的小学妹 提交于 2019-12-04 03:54:41
问题 I've been working through this problem for several hours, and I've made significant progress (thanks in large part to searching this site and applying tips found in similar questions) but I now seem to be at an impasse. Please take a look through what I have done and either point out where I've gone wrong and provide psuedo code to correct, or point me to a resource that can help me by filling in the gap of my understanding. I really feel as though I'm just missing a tiny detail that will

Can I pass Promises to jQuery.when(), or only Deferreds?

旧城冷巷雨未停 提交于 2019-12-04 03:46:25
问题 The documentation for jQuery.when() says that this function takes Deferreds. However, it also says later on that: If a single argument is passed to jQuery.when() and it is not a Deferred or a Promise... which seems to imply that it can take Promises as well. But Promises are not Deferreds - they have a subset of the Deferred's methods. I guess you could say that a Deferred is a Promise, but a Promise is not a Deferred. Questions: Can $.when() take either Promises or Deferreds? This seems to