Using Lambda with variables in deriving class: Regression or not?

Jonathan Wakely jwakely.gcc@gmail.com
Fri Feb 17 12:06:00 GMT 2012


On 17 February 2012 10:30, Deniz Sarikaya wrote:
>
> As a workaround I turned
>
> [&variable]() -> void
> {
>     variable->memfunc();
> }
>
> to
>
> [&]() -> void
> {
>     variable->memfunc();
> }
>
>
> Did I do something wrong or why is this not working anymore?

I'm guessing the problem has nothing to do with derived classes, it's
that identifiers in the capture-list must be local variables or 'this'
so to capture a member you must capture 'this'

So you probably want:

[this]() -> void
{
    variable->memfunc();
}

GCC 4.6 accepted incalid captures but that was probably changed by the
fix for http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50736



More information about the Gcc-help mailing list