Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible error in Capture List and Classes #6

Closed
lopezzot opened this issue Mar 11, 2023 · 4 comments
Closed

Possible error in Capture List and Classes #6

lopezzot opened this issue Mar 11, 2023 · 4 comments

Comments

@lopezzot
Copy link

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;
}
@lopezzot
Copy link
Author

And perhaps another little mistake in 03.Basic_Concepts_II.pdf slide 17.

struct A {int x; int y;};
A array[10] = { {1,2}, {5,6}, {7,1} };
for (auto [x1, y1] : array) cout<<x1<<","<<y1<<" "; //print:1,2 5,6 7,1

I suppose it is A array[] instead of A array[10]. Otherwise it prints

1 2
5 6
7 1
0 0
0 0
0 0
0 0
0 0
0 0
0 0

@lopezzot
Copy link
Author

And maybe another one in 07.Object_Oriented_II.pdf slide 26.

static_cast<B&>(a1).f(); // print "A" downcasting

It actually prints "B", not "A". I suppose you meant:

static_cast<B&>(a).f(); // print "A" downcasting

@federico-busato
Copy link
Owner

Hi @lopezzot, many thanks for pointing out all these issues. I will fix them soon.

@lopezzot
Copy link
Author

You are welcome and thanks for this excellent course.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants