我遇到了这个问题,我有一个 map<int, vector<int> > graph
我试图访问 graph[i].begin()
其中 int i = 0;
, 无法解决。
错误是:
error: no viable overloaded operator[] for type 'const map<int, vector<int> >
谁能解释一下?谢谢!
最佳答案
operator[]
不是 const
成员,因此不能应用于 const map
。
为什么 operator[]
是非常量?因为如果元素不存在,它会将元素插入到 map 中(这会修改 map )。
关于c++ - map<int, vector<int>> graph 和 graph[i].begin() 无法解析,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24559666/