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
  • 6,610
  • 6
  • 40
  • 90

0 Answers0