2

I'm using C++11, why is the first case working while the second needs 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;
}
Dean
  • 5,852
  • 3
  • 32
  • 78

0 Answers0