Multimap和shared_ptr

时间:2011-04-10 08:19:24

标签: c++ boost function-pointers multi-index

我想在boost::multi_map中对我的对象进行排序,参考一些索引。但是我存储的不是纯粹的对象,而是包含在boost::shared_ptr中。这是代码:

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;

但它失败了:&boost::shared_ptr<Object>::getIndex。这在逻辑上是,该类型没有getIndex功能。但是如何以这种方式引用该功能呢?

我用简单的Object::getIndex尝试了它:

could not convert template argument ‘&Object::getIndex’ to ‘int (boost::shared_ptr<Object>::*)()’

1 个答案:

答案 0 :(得分:2)

更改

boost::multi_index::mem_fun<boost::shared_ptr<Object>, int, &boost::shared_ptr<Object>::getIndex>

boost::multi_index::mem_fun<Object, int, &Object::getIndex>

根据documentation它应该有用。