Tag: c11
-
Lambda passed by reference runs when invoked in the constructor, but not when later stored in a data member
27 The following C++ code prints 11.1 then crashes. The lambda function seems to be called correctly inside the constructor, but then later, that same function no longer works! Why is this? Does the lambda have a limited lifespan? #include <functional> #include <iostream> class LambdaStore { public: LambdaStore(const std::function<void(float)>& _fn) : fn(_fn) { fn(11.1f); //…