在.h中
typedef struct
{
char* name
int args;
double (*func)();
} FUNCTION;在.cpp中
FUNCTION Funcs[] =
{
{ "sin", 1, sin },
{ "cos", 1, cos },
{ "tan", 1, tan },
.....
};
我想根椐字串name找到函数的地址,FUNCTION 结构中依次为:函数名,参数个数,函数地址
这样我在处理字串比如"sin"时就能通过Funcs找到具体的函数地址。
以前这是一个.c文件,在VC6下编译,好使。
可是文件换成.cpp后在VC6下编译不通过。
错误如下:
error C2440: 'initializing' : cannot convert from '' to 'double (__cdecl *)(void)'
None of the functions with this name in scope match the target type若把sin,cos等函数前加上&,如下
FUNCTION Funcs[] =
{
{ "sin", 1, &sin },
{ "cos", 1, &cos },
{ "tan", 1, &tan },
.....
};
则会产生以下错误:
error C2440: 'initializing' : cannot convert from 'double (__cdecl *)(double)' to 'double (__cdecl *)(void)'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
这好像离正确很近了,但还是不行。请问我该怎么改代码?
typedef struct
{
char* name
int args;
double (*func)();
} FUNCTION;在.cpp中
FUNCTION Funcs[] =
{
{ "sin", 1, sin },
{ "cos", 1, cos },
{ "tan", 1, tan },
.....
};
我想根椐字串name找到函数的地址,FUNCTION 结构中依次为:函数名,参数个数,函数地址
这样我在处理字串比如"sin"时就能通过Funcs找到具体的函数地址。
以前这是一个.c文件,在VC6下编译,好使。
可是文件换成.cpp后在VC6下编译不通过。
错误如下:
error C2440: 'initializing' : cannot convert from '' to 'double (__cdecl *)(void)'
None of the functions with this name in scope match the target type若把sin,cos等函数前加上&,如下
FUNCTION Funcs[] =
{
{ "sin", 1, &sin },
{ "cos", 1, &cos },
{ "tan", 1, &tan },
.....
};
则会产生以下错误:
error C2440: 'initializing' : cannot convert from 'double (__cdecl *)(double)' to 'double (__cdecl *)(void)'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
这好像离正确很近了,但还是不行。请问我该怎么改代码?
解决方案 »
- 新手求教大家一个MFC动态dll对话框值传递的问题
- 请问自绘按钮时为什么ODS_HOTLIGHT永远没反应
- 不知道是不是范围的问题
- 不同类间数据的传递
- 请教:看《windows程序设计》遇到的问题。
- 我的系统是C/S结构,我想把客户端封装的计算公式类,转移到SQL SERVER2000上,作为存储过程,然后客户端传递参数给过程,但是好象并没有减轻客
- EDIT 怎样输入小数?怎样以回车来表示输入结束来进行下一个输入?
- 请问怎么得到MDI子窗体当前的状态是最大化还是正常或最小化?时间紧急!在线等待!
- 请问CListCtrl如何实现选中一行。多谢
- 进程内DLL还需要代理/占位DLL吗?
- 一个奇怪的问题
- 怎样把鼠标焦点,从左上角移动到左下角???
FUNCTION Funcs[] =
{
{ "sin", 1, (double (*)())(&sin) },
{ "cos", 1, (double (*)())(&cos) },
{ "tan", 1, (double (*)())(&tan) },
.....
};
得强制转换一下,比严格多了。