R
Ralf Goertz
Hi,
why doesn't this compile?
#include <vector>
int main() {
std::vector<bool> v(10,true);
bool& br=v[3];
}
g++ complains:
error: invalid initialization of non-const reference of type ‘bool&’
from a temporary of type ‘std::_Bit_reference’
But there are two overloads of [] for std::vector, one reference and one
const reference. So why doesn't the compiler pick the nonconst
reference? Also, neither using at nor dereferencing begin() works.
why doesn't this compile?
#include <vector>
int main() {
std::vector<bool> v(10,true);
bool& br=v[3];
}
g++ complains:
error: invalid initialization of non-const reference of type ‘bool&’
from a temporary of type ‘std::_Bit_reference’
But there are two overloads of [] for std::vector, one reference and one
const reference. So why doesn't the compiler pick the nonconst
reference? Also, neither using at nor dereferencing begin() works.