作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在玩一些 boost 容器,但最近遇到了障碍,因为我似乎无法正确定义 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;
}
我有一种预感,我没有为此包含一个文件,但我找不到解决方案。
最佳答案
应该这样做:
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
期望一个 gloabl 函数。 &node::numerical
和&node::data
一样都是一个成员。您当然可以编写一个接受节点并提取它的函数,但为什么要这样做呢?
您还缺少 member.hpp
包含。
关于c++ - 无法定义 multi_index_container ordered_non_unique,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16545502/
我正在玩一些 boost 容器,但最近遇到了障碍,因为我似乎无法正确定义 multi_index_container。我正在按照我离线抓取的示例进行操作,但它仍然给我错误消息: struct boos
我有一个 boost::multi_index_container 由一个 ordered_non_unique 键索引并排序。当我遍历非唯一索引时,条目按照它们添加到容器中的顺序出现,而不是它们在序
我是一名优秀的程序员,十分优秀!