c++ - 传递一个函数和一个整数的函数。警告 : passing argument of "" from incompatible pointer type

标签 c++ c function debugging

所以,这是代码:

void pass(void(), int);
void hello(int);

int main(void)
{
pass(hello,0);

return 0;
}

void pass(void rfunc(),int a)
{
rfunc(a);
}

void hello(int a)
 {
printf("%d",a);
}

“0”的输出按预期打印。但是,我收到了这些警告,我正在尝试修复这些警告。错误提示:

in function 'main':
warning: passing argument 1 of 'pass' from incompatible pointer  type

如何修复此警告?

最佳答案

pass 的第一个参数需要一个 void (*)() 类型的函数指针,但您传入的是 void 类型的函数指针(*)(int)。这是不兼容的类型。

更改 pass 的参数以接受正确的类型:

void pass(void(int), int);
...
void pass(void rfunc(int),int a) 
{
    ...

关于c++ - 传递一个函数和一个整数的函数。警告 : passing argument of "" from incompatible pointer type,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42865164/

相关文章:

c++ - 检查 Char 是否在范围内

c - 这段 C 代码有什么问题?奇怪的错误

python - 使用函数的输出作为另一个函数的输入 python 编码新手

c++ - 复制列表和关联的迭代器

c++ - 使用 C++ 安装驱动程序

c - 具有不同定义的类型转换结构

c - 如何在结构成员数组中应用限制指针类型关键字?

python - numpy.r_ 不是函数。它是什么?

javascript - 命名函数在 JavaScript 中被低估了吗?

c++ - 通过c中的指针传递二维数组时出错