我使用C ++ 11,为什么第一种情况有效,第二种情况需要auto&&
?
#include <vector>
#include <iostream>
struct Obj {
};
int main()
{
std::vector<Obj> vobj(10);
for (auto& e : vobj) // Works
std::cout << "Yes";
std::vector<bool> v(10, false);
for (auto& e : v) // Fails
e = true;
}