So basically i have an std::vector container that contains bool values (true, false), and i need an operator[] for it, but when i return the value(bool) with the right index, it gives me an error like this: cannot bind non-const lvalue reference of type 'bool&' to an rvalue of type 'bool'|
my operator looks like this:
bool& operator[] ( unsigned int idx) {
typename std::vector<bool>::iterator retval;
for (typename std::vector<std::vector<bool> *>::iterator it = data.begin(); it != data.end(); ++it) {
for (typename std::vector<bool>::iterator cont_it = (*it)->begin(); cont_it != (*it)->end(); ++cont_it) {
if (idx == 0) {
retval = cont_it;
}
idx--;
}
}
return *retval;
}
and the call what gives error:
ivb[0] = false;
ivb[1] = true;
std::vector<bool>
is special. One way that's it's special is that you can't dereference astd::vector<bool>::iterator
and get abool&
. I guess you should have something likestruct bool_wrapper { bool value; }
and then you can usestd::vector<bool_wrapper>
instead. - johnauto
instead oftypename std::vector<std::vector<bool>*>::iterator
? - Jarod42