mercredi 5 août 2015

Variable cannot be implicitly captured in a lambda with no capture-default specified

I'm following this guy's blog post on C++ Lambdas http://ift.tt/1iDTYRN and while compiling his code, I ran into a compiler error:

variable 'unit' cannot be implicitly captured in a lambda with no capture-default specified"

The lines that it is referencing are below:

auto unit = [](auto x) {
    return [=](){ return x; };
};
auto stringify = [](auto x) {
    stringstream ss;
    ss << x;
    return unit(ss.str());
};

The guy seems like he knows about the new Lambda features in C++, which I certainly do not, which is why I am here now. Can someone shed some light on this problem? What do I need to do to get this code compiling correctly?

Thanks in advance! :)

Aucun commentaire:

Enregistrer un commentaire