看,我有两个函数,一个是获取一个字符,另一个是像这样放置一个字符。
void function_get_char (input);
void function_put_char (output);
我有一个指向这些函数的函数指针。
void (*function_operators[])(input_or_output) = {function_get_char, function_put_char};
我需要,当我调用我的 function_operator 时,我不想指定我是想在输出中获取它还是在我的输入中获取它。
我需要像这样构建我的函数指针吗?
void (*function_operators[])(input_or_output) = {function_get_char(input), function_put_char(output)};
我该怎么做? 提前致谢。
注意
输入或输出参数,不是run_time参数。
最佳答案
我不太确定你想做什么,但如果你想将 input
和 output
修复为某个预定义的值(因为你说它们不是运行时的参数),最简单的解决方案应该是编写一些包装函数,用正确的参数调用“真实”函数。例如:
void fixed_get_char(void) { function_get_char(input); }
void fixed_put_char(void) { function_put_char(output); }
void (*function_operators[])(void) = {fixed_get_char, fixed_put_char};
关于c - C中带默认参数的函数指针,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2860781/