Can someone explain to me why the following does not work (test is const inside of blub). Since test is copied by value I was assuming, I could set it since it is functor local.
#include <memory>
int main()
{
std::shared_ptr<bool> test;
auto blub = [test]() {
test = std::make_shared<bool>(false);
};
return 0;
}
To make this working, first I have to introduce a new shared_ptr, assign test and then I can normally assign the other shared_ptr.
BTW: I am using clang 3.1
Because the
operator()of lambdas isconstby default. You need to use themutablekeyword to make it non-const: