首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >C++ boost::bimap ()方法无法工作

C++ boost::bimap ()方法无法工作
EN

Stack Overflow用户
提问于 2019-07-03 08:35:46
回答 1查看 182关注 0票数 0

我试图在boost::bimap中插入数据,但是给出了一个错误。

代码语言:javascript
复制
typedef boost::bimap<std::string, std::string> bimap_type;
bimap_type _obs_ids;

void store_domains_obs_ids(const std::string & name, const std::string & obs_id) const
{
    _obs_ids.insert(bimap_type::value_type(name, obs_id));
}

错误::

代码语言:javascript
复制
no instance of overloaded function "boost:thimaps::bimap<KeyTypeA, KeyTypeB, AP1, AP2, AP3>::insert [with KeyTypeA= std::string, KeyTypelhstd::string, AP1=boost::mpl::na, AP2= boost::mpl::na, AP3= boost:mph:na]" matches the argument list and object (the object has type qualifiers that prevent a match) argument types are: (boostthimapsuelation::mutant_relation<boostthimaps::tags::tagged<const std::string, boost:thimapsuelation::member_athleft>, boost::bimaps::tags::tagged<const std::string, boostthimapsuelation::member_athright>, boost::mpl::na, false>) object type is: const ipm::config::bimap_type
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-07-03 09:02:40

您必须从成员函数签名中删除const

代码语言:javascript
复制
void store_domains_obs_ids(const std::string & name, const 
std::string & obs_id) const
{}

应该是

代码语言:javascript
复制
void store_domains_obs_ids(const std::string & name, const 
std::string & obs_id) 
{}

在const成员函数中,_obs_ids被视为const对象,对于const对象,您只能调用const函数成员。因为insert修改了bimap实例,所以只能从非const函数调用该函数。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56866053

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档