Multimap and shared_ptr
I want to sort my objects in boost::multi_map
refer to some index. But I'm开发者_JS百科 storing not pure objects, but wrapped into boost::shared_ptr
. Here is the code:
typedef boost::multi_index_container<boost::shared_ptr<Object>,
boost::multi_index::indexed_by<
boost::multi_index:: ordered_non_unique<
boost::multi_index::mem_fun<boost::shared_ptr<Object>, int, &boost::shared_ptr<Object>::getIndex>
>
>
> ObjectWrapperSet;
But it fails at point: &boost::shared_ptr<Object>::getIndex
. This is logically, that type doesn't have getIndex
function. But how to refer to that function this way?
I tried it with simple Object::getIndex
:
could not convert template argument ‘&Object::getIndex’ to ‘int (boost::shared_ptr<Object>::*)()’
Change
boost::multi_index::mem_fun<boost::shared_ptr<Object>, int, &boost::shared_ptr<Object>::getIndex>
to
boost::multi_index::mem_fun<Object, int, &Object::getIndex>
According to the documentation it should work.
精彩评论