【发布时间】:2019-03-14 11:40:54
【问题描述】:
我有两个函数调用
void funcBlock(A a, B b, int C, long& R, long& M, double& D)void funcNormal(A a, B b, long& R, long& M, double& D)
在 main 方法中,我想通过循环使用这两个函数的值,例如,
主要方法:
combineFunc cfs[] = { funcBlock, funcNormal }
for (int idx = 0; idx < 2; idx++) //Cause it has two functions to loop over
{
combineFunc cf = cfs[idx];
//Do the rest of the stuffs
}
我遇到错误:
错误:初始化时无法将‘void (*)(A, B, int, long int&, long int&, double&)’转换为‘combineFunc’
我该如何解决这个问题?
【问题讨论】:
-
什么是
combineFunc? -
它们接受不同的参数类型和不同数量的参数。您如何期望代码知道要传递哪些参数和传递多少参数?
-
最好告诉我们你想达到什么目标。
-
cfs[]是一个数组。数组的所有元素都必须属于同一类型。 “函数指针”不是一种类型。每个函数指针必须是同一类型。
标签: c++ arrays function pointers