struct MyObj { int value{ 123 }; auto getValueCopy() { return [*this] { return value; }; } auto getValueRef() { return [this] { return value; }; } };
MyObj mo; auto valueCopy = mo.getValueCopy(); auto valueRef = mo.getValueRef();
mo.value = 31; valueCopy(); // 123
valueRef(); // 321
std::array<int, 5> a{ 1, 2, 3, 4, 5 }; for (int& x : a) { x = 2*x + 1; }
#include <iostream>
for(auto const& x: a) { std::cout << x << " "; }
int i; for (i = 0; i < 10; i++) {} int x = i; std::cout << x;
int y; std::cin >> y; 2 * y + 1
Interpreter Error: