【发布时间】:2014-01-16 12:44:21
【问题描述】:
是否有可能使用函数指针来寻址具有相同返回类型的不同参数的函数,如果没有任何替代方法会有所帮助..提前谢谢
示例:
struct method
{
char *name;
void (*ptr)(?); //? : what to define as arguments for this
};
void fun1(char *name)
{
printf("name %s\n\r",name);
}
void fun2(char *name, int a)
{
printf("name %s %d\n\r",name,a);
}
//defined before main()
method def[]=
{
{"fun1",fun1},
{"fun2",fun2}
}
//some where in main()
//call for function pointer
def[1].ptr("try", 2);
【问题讨论】:
-
对于具有相同函数签名的函数,您只能使用指向函数的指针。
-
这看起来像是一开始就失败的解析问题:en.wikipedia.org/wiki/…
标签: c++ c pointers function-pointers