Monday, October 8, 2007

Function Object is function pointer in C

Yes boss it is same as function pointer
Lets have an example

template "<" class T >
struct ADD
{
T operator()(T n,T n1)
{
return n+n1;
}
};

template "<" class T, class funcObj ">"
void printEval(T val,T val1,funcObj f)
{
cout <<>" ());
printEval(1.4,1.6, ADD "<" float ">" ());
return 0;
}
It is self explanatory. Do you want me to explain.? :)
I have compiled using gcc version 2.96 and redhat 7.1
It is working fine.

No comments: