I want to define a lambda based on the value of a variable, so I am using a switch statement.
However, I can't seem to work out how to type the variable that holds the lambda.
I've tried this:
auto valueFunction = [](int s, int d, int ct, int tt) { return -1; };
switch (changeMethod) {
case VeloChangeMethod::EXPONENTIAL_GROWTH:
valueFunction = [](int s, int d, int ct, int tt) { return /* maths goes here */ };
case VeloChangeMethod::EXPONENTIAL_DECAY:
valueFunction = [](int s, int d, int ct, int tt) { return /* maths goes here */ };
case VeloChangeMethod::NORMAL:
default:
valueFunction = [](int s, int d, int ct, int tt) { return /* maths goes here */ };
break;
}
and also just defining:
auto valueFunction;
But, with the above code, as soon as it tries to reassign valueFunction, the compiler errors (no match for operator "=").
So, how can I create a lambda inside a switch statement, and retain it for use after the switch statement is finished?