【发布时间】:2018-03-26 07:38:07
【问题描述】:
Visual Studio 在这段代码中给了我错误
typedef union
{
double value;
double (*UnFunc)(double);
double (*BiFunc)(double, double);
double (*VarAssi)(vars_t *, elem_t, elem_t, error_t *);
void (*FuncAssi)(custom_funcs_t *, elem_t, expr_t, error_t *);
char delimiter;
} body_t;
typedef struct
{
const char *name;
int priority;
body_t body;
} elem_info_t;
static const elem_info_t s_STD_UN_FUNC[] = {
{"sqrt", 2, sqrt},
{"sin", 2, sin},
{"cos", 2, cos},
{"tg", 2, tan},
VS 说(下划线功能分配)
错误 C2440: '正在初始化': 无法从 'double (__cdecl *)(double)' 到 'double'
但是联合类型中已经存在所有类型的指针。显式类型转换会导致另一个错误。在这种情况下我应该怎么做?谢谢。
【问题讨论】:
-
请显示 sqrt、sin 等的定义
-
如果在
union中将double (*UnFunc)(double);放在double value;之前会发生什么?顺便说一句,我希望你有充分的理由使用union。它们可能有问题(您的代码就是一个例子)。 -
那个地方的错误会消失,但在其他所有由其他类型的函数定义的地方,错误会一直存在。
-
sqtr 等来自 math.h
-
发布的代码缺少类型的定义:elem_t、error_t、expr_t、custom_funcs_t,并且'body_t`的typedef失败。
标签: c visual-studio