我想建立一个快捷方式用于制备类似的功能调用C++级联和strinization操作者
int g[2];
void f1() {
g[0] = 1;
}
void f2() {
g[1] = 2;
}
void (*f)();
由于函数f1,f2的有一些共同的图案,我可以通过下的快捷++级联(##)和strinization(#)运算符或别的东西有这样的:使用函数指针数组
for (int i = 0; i < 2; i++) {
// have to do something to get the function name formed like f1, f2
// and then assign f to f1 or f2 and call f, based on value of i
// need help in this portion
}
但为什么不将索引作为常规参数传递给函数? –