警告初始化来自不兼容的指针类型-C函数指针数组
我无法解决此警告 这是我的原型警告初始化来自不兼容的指针类型-C函数指针数组,c,function,pointers,initialization,function-pointers,C,Function,Pointers,Initialization,Function Pointers,我无法解决此警告 这是我的原型 int doubeInput (int* inputVal); int squareInput (int* inputVal); int cubeInput (int* inputVal); 出现错误的行是 int (*funPtrArr[])(int)={doubleInput, squareInput, cubeInput}; 这条线是主要的 while (choice >0 && choice <=3) {
int doubeInput (int* inputVal);
int squareInput (int* inputVal);
int cubeInput (int* inputVal);
出现错误的行是
int (*funPtrArr[])(int)={doubleInput, squareInput, cubeInput};
这条线是主要的
while (choice >0 && choice <=3)
{
(*funPtrArr[choice])(inputVal);
}
我不断地遇到这个错误,我对C非常陌生。我的函数还没有完成,因为我还没有能够测试它们。
请帮忙
int (*funPtrArr[])(int)
声明指向具有int
参数的函数的指针数组,但函数具有int*
参数。
所以这条线应该是
int (*funPtrArr[])(int *)={doubleInput, squareInput, cubeInput};
好的,这确实消除了这些错误,但现在我得到了另一个[Warning]传递参数1“funPtrArr[choice]”从整数生成指针而不进行强制转换。main()中的
inputVal
的类型是什么?如果是int
,则必须传递&inputVal
输入错误:intdoubeinput(int*inputVal)代码>必须是双输入
。
int (*funPtrArr[])(int *)={doubleInput, squareInput, cubeInput};