dynamic functions

Hi guys,

I want to call a function that returns a function. I can use syntax like

float (*GetPtr1(const char opCode))(float, float)
{
if(opCode == '+')
return &Plus;
else
return &Minus; // default if invalid operator was passed
}

but that supposes I have Plus and Minus predefined. What if I want to return a "dynamically generated" function that returns (say) a times the first argument plus b times the second? The code in python would be

def funcMaker(a, b):
return lambda(x,y: a*x + b*y)

Lambda expressions are not part of C++98 ( they will be in C++0x )
You can look for boost::lambda ( a library used to do this with the current standard )
Thanks Bazzy. Though on inspection lambda functions in C++ look hideous.
There is also boost::lambda. The syntax is slightly different. You might consider it better. Or maybe worse.

Why are you concerned about the functions Plus and Minus having to pre-exist?
Topic archived. No new replies allowed.