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?

4

1 に答える 1

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

各インデックスは ( 経由で) 個別にアクセスされget、独自のメンバー関数、イテレータなどがあります ( を使用できない場合autoitはタイプです。) ドキュメントチュートリアルCntr::nth_index<1>::type::iteratorの詳細情報。

于 2014-07-22T08:08:13.533 に答える