Skip to content

Possible error in Capture List and Classes #6

@lopezzot

Description

@lopezzot

Dear Federico,

perhaps an error in 05.Basic_Concepts_IV.pdf slide 33.

auto lambda3 = [this]() { return data; }; // copy by-reference, return 2

it returns 1, not 2.
For instance, the following prints 1 with -std=c++20:

#include <iostream>

class A {
    public:
        int data = 1;

        void f(){
            int var = 2;
            auto lambda3 = [this](){return data;};
            std::cout<<lambda3()<<std::endl;
        }
};   

int main(){
    A a;
    a.f();
    return 0;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions