0

I am trying to store objects in a boost multi-index container.

These objects are all unique can be retrieved by 2 separate keys (unique as well).

namepsace bm = boost::multi_index;

class MyObj {
 string  strid_;
 int32_t numid_;
};

//! associative container searchable by ClOrdId and Sunofia Id.  
typedef boost::multi_index_container< MyObj,
bm::indexed_by<
  bm::ordered_unique<
    bm::member<MyObj,string,&MyObj::strid_>
  >,
  bm::ordered_unique<
    bm::member<MyObj,int32,&MyObj::numid_>
  >
>            
> Cntr;
Cntr cntr_;   

When I try to find any element of that index by integer I use the following code

 int32_t to_find = 12;
 Cntr::iterator it = cntr_.find(id);

but it doesn't compile and I get the following error

error: invalid conversion from ‘int’ to ‘const char*’

When I use the same code with string it works fine; do you know what I am doing wrong?

Abruzzo Forte e Gentile
  • 14,423
  • 28
  • 99
  • 173

1 Answers1

2
auto it = cntr_.get<1>().find(id);

Each index is accessed separately (via get) and has its own member functions, iterators, etc. (In case you can't use auto,it is of type Cntr::nth_index<1>::type::iterator.) More info on the doc tutorial.

Joaquín M López Muñoz
  • 5,243
  • 1
  • 15
  • 20