Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multimap and shared_ptr

I want to sort my objects in boost::multi_map refer to some index. But I'm 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>::*)()’
like image 883
Max Frai Avatar asked Dec 01 '25 04:12

Max Frai


1 Answers

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.

like image 110
Yakov Galka Avatar answered Dec 03 '25 18:12

Yakov Galka



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!