无法定义multi_index_container ordered_non_unique

时间:2013-05-14 14:11:22

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

我正在玩一些增强容器,但我最近遇到了封锁,因为我似乎无法正确定义multi_index_container。我正在关注一个我离线抓住的例子,但它仍然给了我和错误信息:

struct boost::multi_index::global_fun<const node&, int, <error-constant>>

Error: Expression must have a constant value

这是我的声明:

#define _CRT_SECURE_NO_DEPRECATE
#define _SCL_SECURE_NO_DEPRECATE
#include <boost/config.hpp>

#include <string>
#include <iostream>

#include <boost/multi_index_container.hpp>
#include <boost/multi_index/key_extractors.hpp>
#include <boost/multi_index/hashed_index.hpp>
#include <boost/multi_index/global_fun.hpp>
#include <boost/multi_index/ordered_index.hpp>
using namespace boost::multi_index;

struct node
{
    node(std::string da, int in) {
        data = da;
        numerical = in;
    };
    std::string data;
    int numerical;
};

int main()
{
    typedef multi_index_container<
        node,
        indexed_by<
            hashed_unique<
                member<node,std::string, &node::data>>,
            ordered_non_unique<
                global_fun<const node&, int, node::numerical>> //right here, the value numerical errors
            >
        > node_type;



}

我有预感,我没有为此包含文件,但我找不到解决方案。

1 个答案:

答案 0 :(得分:1)

这应该这样做:

typedef multi_index_container<
  node,
  indexed_by<  hashed_unique< member<node,std::string, &node::data> >
             , ordered_non_unique< member<node, int, &node::numerical> >
            >
  > node_type;

global_fun预计会有一个全面的功能。 &node::numerical&node::data的成员。您当然可以编写一个接受节点并提取它的函数,但为什么会这样?

您也错过了member.hpp include。

相关问题