I just tested this piece of code.
vector<bool> v(5, true);
if(v.back())cout<<"====="<<endl;
auto b1 = v.back();
b1 = false;
cout<<&b1<<endl;
if(v.back())cout<<"*********"<<endl;
My questions are following:
- "*********" (no quotes) doesn't appear in the output, why the variable declared by
autois changing the bool vectorv? - I understand that
vector<bool>is not a standard STL container, and addressing the element of it by&v[4]won't work(since you can not address the address of a bit), ifb1is declared by a reference tov.back(), why I can addressb1by&b1? - In what cases
autohas this kind of behavior? Doesauto c1 = v.begin()and later doingc1 = (++v.begin())will changev.begin()?