c++ - Multimap 和 shared_ptr

标签 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>::*)()’

最佳答案

改变

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

关于c++ - Multimap 和 shared_ptr,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5610562/

相关文章:

c++ - 函数指针 - 无法更改函数签名,我有什么选择?

c++ - wchar_t 在一般编程中有什么用?

c++ - 在 C/C++ 中是否有类似极度优化的 memcpy2d 之类的东西?

java - 使用 android NativeActivity 时从 SoftInput 接收所有 unicode 字符

c++ - 将 error_info 添加到 std::exception

c++ - 如何在断开连接后干净地重新连接 boost::socket?

c - 如何在 C 上实现一组函数?

c# - 找到围绕某个点形成四面体的 4 个点

c++ - STL/boost 方法为 vector 中的每个对象重复间接调用方法

c++ - 多态成员函数指针