C++ 访问地图元素

C++ 访问地图元素,c++,map,constants,std,C++,Map,Constants,Std,我尝试返回std::map的特定对象,如下所示: const Vertex& Graph::getVertex(const std::pair<size_t, size_t>& pos) const // -> compile error { return this->_vertices[std::get<0>(pos)][std::get<1>(pos)]; } const-Vertex&Graph::getVertex(

我尝试返回std::map的特定对象,如下所示:

const Vertex& Graph::getVertex(const std::pair<size_t, size_t>& pos) const // -> compile error
{
   return this->_vertices[std::get<0>(pos)][std::get<1>(pos)];
}
const-Vertex&Graph::getVertex(const-std::pair&pos)const/->编译错误
{
返回此->_顶点[std::get(pos)][std::get(pos)];
}
地图:

std::map\u顶点;
但是,如果我让getVertex函数的常量为零,则会出现编译错误。这是否意味着以这种方式访问我的地图元素实际上会修改其实例?有更好的方法访问我的地图元素吗

错误:

error: passing ‘const std::map<unsigned int, std::vector<Vertex> >’ as ‘this’ argument of ‘std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type& std::map<_Key, _Tp, _Compare, _Alloc>::o\
   perator[](const key_type&) [with _Key = unsigned int; _Tp = std::vector<Vertex>; _Compare = std::less<unsigned int>; _Alloc = std::allocator<std::pair<const unsigned int, std::vector<Vertex> > >; std::map\
   <_Key, _Tp, _Compare, _Alloc>::mapped_type = std::vector<Vertex>; std::map<_Key, _Tp, _Compare, _Alloc>::key_type = unsigned int]’ discards qualifiers [-fpermissive]
错误:将'const std::map'作为'std::map::mapped_type&std::map::o'的'this'参数传递\
运算符[](const key_type&)[带_key=unsigned int;_Tp=std::vector;_Compare=std::less;_Alloc=std::分配器;std::map\
::mapped_type=std::vector;std::map::key_type=unsigned int]'丢弃限定符[-fppermissive]

getVertex
是常量成员函数

this->_顶点[std::get(pos)][std::get(pos)]
可以在关键点不存在时使用修改
\u顶点
贴图,因此会出现错误

error: passing ‘const std::map<unsigned int, std::vector<Vertex> >’ as ‘this’ argument of ‘std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type& std::map<_Key, _Tp, _Compare, _Alloc>::o\
   perator[](const key_type&) [with _Key = unsigned int; _Tp = std::vector<Vertex>; _Compare = std::less<unsigned int>; _Alloc = std::allocator<std::pair<const unsigned int, std::vector<Vertex> > >; std::map\
   <_Key, _Tp, _Compare, _Alloc>::mapped_type = std::vector<Vertex>; std::map<_Key, _Tp, _Compare, _Alloc>::key_type = unsigned int]’ discards qualifiers [-fpermissive]