Consider this pseudo-snippet:
class SomeClass
{
public:
SomeClass()
{
if(true)
{
fooCall = [](auto a){ cout << a.sayHello(); };
}
else
{
fooCall = [](auto b){ cout << b.sayHello(); };
}
}
private:
template<typename T>
std::function<void(T)> fooCall;
};
What I want is a class member fooCall
which stores a generic lambda, which in turn is assigned in the constructor.
The compiler complains that fooCall
cannot be a templated data member.
Is there any simple solution on how i can store generic lambdas in a class?
See Question&Answers more detail:os