开发者

Multimap and shared_ptr

开发者 https://www.devze.com 2023-02-23 02:40 出处:网络
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:

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消