function-parameter

Error: Initializing Argument 1 of [closed]

*爱你&永不变心* 提交于 2020-01-06 14:47:27
问题 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 5 years ago . I've looked around and seen quite a few of these, but none of them provided the solution for my problem. I'm getting this compilation error with the following code: THE ERROR: THE CODE: const int TOP_WORDS = 25; ... void topWords(Hash t, string word, string topA[]); int main() { ... Hash table1; string word =

Declaring parameter of a function as final: why and when is it needed?

六月ゝ 毕业季﹏ 提交于 2020-01-03 15:56:37
问题 Going through a tutorial for android (related to multithreading, loopers and handlers), i came across this: public synchronized void enqueueDownload(final DownloadTask task) My questions are: When and why is it needed to declare a parameter of a function as final? Is it specific to Java or does something similar exist in other languages such as C/C++? 回答1: In Java this is usually so that you can access the parameter within an anonymous inner class - which is often used in Android for event

What's this usage of the variable cast to void in function body?

一世执手 提交于 2020-01-03 06:51:32
问题 I am just learning to code embedded C. I see some code like below. The function is defined like this: void printDebug(const char d1[]){(void)d1;} And it is used like this: printDebug("BLE_UART_EVENT"); I don't understand its purpose. It gives me an impression of a callable char array? 回答1: It's not calling char array, it's just explicitly converting the char array to void . (And the evaluated result is discarded immediately.) I think it's just used to prohibit the compiler warning of unused

Variadic templates without function parameters

你。 提交于 2020-01-02 02:01:08
问题 Can I use variadic templates without using the template parameters as function parameters? When I use them, it compiles: #include <iostream> using namespace std; template<class First> void print(First first) { cout << 1 << endl; } template<class First, class ... Rest> void print(First first, Rest ...rest) { cout << 1 << endl; print<Rest...>(rest...); } int main() { print<int,int,int>(1,2,3); } But when I don't use them, it doesn't compile and complains about an ambiguity: #include <iostream>

How to deal with name/value pairs of function arguments in MATLAB

瘦欲@ 提交于 2019-12-27 18:20:56
问题 I have a function that takes optional arguments as name/value pairs. function example(varargin) % Lots of set up stuff vargs = varargin; nargs = length(vargs); names = vargs(1:2:nargs); values = vargs(2:2:nargs); validnames = {'foo', 'bar', 'baz'}; for name = names validatestring(name{:}, validnames); end % Do something ... foo = strmatch('foo', names); disp(values(foo)) end example('foo', 1:10, 'bar', 'qwerty') It seems that there is a lot of effort involved in extracting the appropriate

How to create a polyvariadic haskell function?

妖精的绣舞 提交于 2019-12-27 11:08:27
问题 I need a function which takes an arbitrary number of arguments (All of the same type), does something with them and afterwards gives a result back. A list of arguments is impracticable in my specific case. As I looked through the haskell libs, I saw that the function printf (from module Text.Printf ) uses a similar trick. Unfortunately, I couldn't understand that magic by looking at the source. Can somebody explain how to achieve this, or at least some webpage/paper/whatever where I could

Why function parameters can not be static

大憨熊 提交于 2019-12-25 02:15:40
问题 Can anyone please tell me that why the functions parameters can not be static ? Is this the reason that function parameters are declared on Stack and gets de-allocated when function return? There is no way to retain parameter values? Just confused. Please clarify. Thanks. 回答1: The keyword static can probably be seen as somewhat "overloaded". The following usage-options are all viable: Static local variables Static global variables Static member variables Static global functions Static member

C: Function to swap values in 2D array

余生颓废 提交于 2019-12-24 20:17:06
问题 I'm trying to write a function to swap 2 elements in a 2D array: void swap(int surface[][], int x1, int y1, int x2, int y2) { int temp = surface[x1][y1]; surface[x1][y1] = surface[x2][y2]; surface[x2][y2] = temp; } however when I try to compile it (gcc), I get this error message: Sim_Annealing.c: In function `swap': Sim_Annealing.c:7: error: invalid use of array with unspecified bounds Sim_Annealing.c:8: error: invalid use of array with unspecified bounds Sim_Annealing.c:8: error: invalid use

Convert function parameter in string into parameter in object

烈酒焚心 提交于 2019-12-24 17:50:02
问题 I am using node.js. I have a function that can be called this way; add_row({location:'L1', row_name:'r1', value:'18.4'}); I have a string like this; var str_param = "location:'L1', row_name:'r1', value:'18.4'"; I tried to do something like this to keep my code simple; add_row(str_param); It did not work. What is a good way to use str_param to call add_row ? 回答1: You could convert the string to an object that the function accepts. function toObj(str) { const a = str.split(/,.?/g); return a

How to pass a string with a few comma separated values as function parameters

时光怂恿深爱的人放手 提交于 2019-12-24 09:30:59
问题 For instance: $str = '1, 2, 4, 13'; I'd like the effect to be as if it were: func(1, 2, 4, 13) 回答1: $params = explode(', ', $str); call_user_func_array("func", $params); 回答2: $str = '1, 2, 4, 13'; function func($one, $two, $three, $four) { var_dump(func_get_args()); } call_user_func_array('func', explode(', ', $str)); Remember, you can pass as many parameters to a function and accessing them with func_get_args(), they dont have to be defined in the methods signature. 来源: https://stackoverflow