Mail Archives: djgpp/1997/09/24/10:15:30
>Is possible to pass operator as function parameter ?
>....like this fantasious example ??...
I'll put in 2 cents worth. Something like this "might" be more straight
forward with a C++ class. However, since I don't know the circumstance I'll
post a C idea.
int My_Func(int, int, char);
int main( )
{
char oper;
int a, b, c;
oper = '+';
a = 10;
b = 5;
c = My_Func(a, b, oper);
return(0);
}
int My_Func(int a, int b, char ch)
{
if(ch == '+')
return(a + b);
else
if(ch == '-')
return(a - b);
..... /* you might even setup a switch( ) ? */
}
- Raw text -