当类型为int时编译正常,但当类型为<时给出“错误C2102:'&'需要左值”强> boolean 。为什么?
std::vector<Type> Vector;
Vector.push_back(false);
Vector.push_back(true);
Vector.push_back(true);
const void* Pointer = NULL;
for (std::vector<Type>::const_iterator it = Vector.begin(); it != Vector.end(); ++it)
Pointer = &(*it);
最佳答案
vector
专门用于bool
,并且在该专业领域中,*it
不是左值。不可能指向个人bool
s 在 vector 内。
事后看来,这种特化被认为是一个错误。现在通常建议避免使用 vector<bool>
。替代方案包括std::bitset
.
关于c++ - 使用 bool 作为左值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34016340/