0

I am trying to insert data in boost::bimap but gives an error.

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));
}

Error::

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
  • Can you show what `name` and `obs_id` refer to? I can't reproduce the issue... – lubgr Jul 03 '19 at 08:38
  • 1
    Welcome to Stack Overflow. Please read [the help pages](http://stackoverflow.com/help), take [the SO tour](http://stackoverflow.com/tour), read about [how to ask good questions](http://stackoverflow.com/help/how-to-ask), as well as [this question checklist](https://codeblog.jonskeet.uk/2012/11/24/stack-overflow-question-checklist/). Lastly please learn how to create a [mcve]. – Some programmer dude Jul 03 '19 at 08:38
  • @lubgr : The value is coming from a method call like (std::string & name, const std::string & obs_id) and values inside the field are like name = "Domain_01" and obs_id = "ae23b458" – Ayan Bhuin Jul 03 '19 at 08:43
  • 1
    I guess your member function (where `_obs_ids.insert` is called) is `const`, isn't it? – rafix07 Jul 03 '19 at 08:48
  • I have added complete function. please check. – Ayan Bhuin Jul 03 '19 at 09:00

1 Answers1

0

You have to remove const from member function signature:

void store_domains_obs_ids(const std::string & name, const 
std::string & obs_id) const
{}

should be

void store_domains_obs_ids(const std::string & name, const 
std::string & obs_id) 
{}

inside const member function, _obs_ids is treated as const object, for const objectes you can call only const function members. Because insert modifies bimap instance, you can call this function only from non-const function.

rafix07
  • 20,001
  • 3
  • 20
  • 33