Why do I get the error: invalid initialization of non-const reference of type ‘bool&’ from an rvalue of type ‘std::vector::reference {aka std::_Bit_reference}’?
vector<vector<bool>> vis;
bool& visited(int x, int y)
{
return vis[x][y]; //error
}
As far as I know operator[] in vector returns reference, so it should be an lvalue, but it doesn't work. What should I do to make it work?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…