Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <memory>
- using namespace std;
- //Will give error
- int main() {
- auto p = make_unique<int>(64);
- auto lambda = []() { //To access some variable declared in the external scope like the p must use the lambda capture list inside the brackets
- cout << " Inside the lambda -- value = " << *p << '\n';
- };
- lambda();
- }
- //Will work
- int main() {
- auto p = make_unique<int>(64);
- auto lambda = [ptr = move(p)]() {
- cout << " Inside the lambda -- value = " << *ptr << '\n';
- };
- lambda();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement