jeudi 3 décembre 2015

Range-based loops for bools

Why does this code work

  vector<int> intVector(10);
  for(auto& i : intVector) cout << i;

And this doesn't?

  vector<bool> boolVector(10);
  for(auto& i : boolVector) cout << i;

In the latter case, I get an error

error: invalid initialization of non-const reference of type ‘std::_Bit_reference&’ from an rvalue of type ‘std::_Bit_iterator::reference {aka std::_Bit_reference}’
   for(auto& i : boolVector) cout << i;

Aucun commentaire:

Enregistrer un commentaire