In this little test program, can someone explain me:
- Why is every addresses printed in both loops the same?
Why is it different from one loop to another?
struct A { A(){ std::cout << &v << "\n"; }; int v; }; int main() { std::vector<A> vec; int i = 10; while (i--) vec.push_back(A()); for (A b : vec) std::cout << &(b.v) << "\n"; while (true); return 0; }
I actually expected to see ten different addresses repeated 2 times