Z
zhybear
I try add some functions like sqrt(), exp() to my structure, and then
perform the compuation of these functions
Here is what i did
typedef struct symtab {
char *name;
double value;
double (*funcptr)();
} symtab;
void addfunc(char *name, double (*func)())
{
symtab *sp = look(name);
sp->funcptr = func;
}
/* symlook is a routine to search if name is already in the table */
main()
{
extern double sqrt(), exp(), log();
addfunc("sqrt", sqrt);
addfunc("exp", exp);
addfunc("log", log);
yyparse();
}
Then I need to perform something like
double k;
(sp->funcptr)(k)
However, g++ complier doesn't like me to do this since it said there
are too many arguments for funcptr (it may be sqrt or exp). How to
avoid this issue?
perform the compuation of these functions
Here is what i did
typedef struct symtab {
char *name;
double value;
double (*funcptr)();
} symtab;
void addfunc(char *name, double (*func)())
{
symtab *sp = look(name);
sp->funcptr = func;
}
/* symlook is a routine to search if name is already in the table */
main()
{
extern double sqrt(), exp(), log();
addfunc("sqrt", sqrt);
addfunc("exp", exp);
addfunc("log", log);
yyparse();
}
Then I need to perform something like
double k;
(sp->funcptr)(k)
However, g++ complier doesn't like me to do this since it said there
are too many arguments for funcptr (it may be sqrt or exp). How to
avoid this issue?