【问题标题】:Multimap and shared_ptrMultimap 和 shared_ptr
【发布时间】:2011-04-10 08:19:24
【问题描述】:

我想对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;

但它失败了:&amp;boost::shared_ptr&lt;Object&gt;::getIndex。从逻辑上讲,该类型没有getIndex 功能。但是如何以这种方式引用该函数?

我用简单的Object::getIndex试了一下:

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

【问题讨论】:

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


    【解决方案1】:

    改变

    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,它应该可以工作。

    【讨论】:

      猜你喜欢
      • 2013-02-27
      • 1970-01-01
      • 1970-01-01
      • 2010-12-07
      • 2012-10-28
      • 2013-06-12
      • 2013-04-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多