定义multi_index_container ordered_non_unique时遇到问题
Trouble defining multi_index_container ordered_non_unique
我正在玩一些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
期望一个全局函数。&node::numerical
和&node::data
一样是成员。当然,您可以编写一个接受节点并提取它的函数,但为什么要这样做呢?
您还错过了member.hpp
包含
相关文章:
- 编译包含字符串的代码时遇到问题
- 为什么 std::unique 不调用 std::sort?
- 遇到新行时,有没有办法停止istream_iterator
- 在使用GPU支持编译Tensorflow时,会遇到CUDA_TOOLKIT_PATH未绑定变量
- 如何在C++向量中奇数元素前面加上值-1,我在使用insert函数时遇到了问题
- 在 for 循环中查找问题时遇到困难
- 创建结构的数组时遇到分段错误
- 代码在我的计算机上运行良好,但是在将其提交给coursera时遇到未知的信号11问题
- 为什么我遇到分段错误?
- 在顶点着色器中使用 OpenGl 的未声明标识符,我在顶点着色器中绘制三角形时遇到问题
- 这些是什么样的错误?即使我不在 Linux 上工作,我也遇到了 Linux 错误
- 为什么我在尝试模板时遇到视觉工作室C++错误
- 如何从文本文件中读取数值,直到遇到字符类型?
- 从其他类访问类时遇到问题
- 我已经阅读了很多关于 2d 数组的信息,但我在作业中使用它时遇到了麻烦
- 打印问题.我在数组中打印值时遇到一些问题
- 使用静态成员声明类时遇到问题
- 创建 Spdlog 异步文件记录器时遇到困难
- C++ 填充数组时遇到问题
- 遇到此问题时遇到困难:允许用户输入数组的值并使用 for,而循环也输出输入的最大数字