提升multi_index示例:错误:二进制表达式的操作数无效
Boost multi_index example: error: invalid operands to binary expression
只是尝试基本的boost::multi_index
示例并接收和错误:
#include <boost/multi_index_container.hpp>
#include <boost/multi_index/ordered_index.hpp>
#include <boost/multi_index/identity.hpp>
#include <boost/multi_index/member.hpp>
using namespace boost::multi_index;
struct employee
{
int id;
std::string name;
employee(int id, const std::string &name) : id(id), name(name) {}
bool operator<(const employee &e) const { return id < e.id; }
};
// define a multiply indexed set with indices by id and name
typedef multi_index_container<
employee,
indexed_by<
// sort by employee::operator<
ordered_unique<identity<employee> >,
// sort by less<string> on name
ordered_non_unique<member<employee, std::string, &employee::name> > > >
employee_set;
void print_out_by_name(const employee_set &es)
{
// get a view to index #1 (name)
const employee_set::nth_index<1>::type &name_index = es.get<1>();
// use name_index as a regular std::set
std::copy(
name_index.begin(), name_index.end(),
std::ostream_iterator<employee>(std::cout)); // Looks like the problem is here.
}
收到此错误:
/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/iterator:813:28: error: invalid operands to binary expression ('ostream_type' (aka
'basic_ostream<char, std::__1::char_traits<char> >') and 'const employee')
*__out_stream_ << __value_;
似乎需要一个实现:
std::ostream &operator<<(std::ostream &os, const employee &obj)
{
os << obj.id << "/" << obj.name;
return os;
}
相关文章:
- 二进制表达式的操作数无效 - 使用 for 和迭代器
- 二进制表达式 cout 问题的无效操作数
- 二进制表达式的操作数无效?
- 二进制表达式的操作数无效("常量字符*"和"常量字符*")
- 如何修复"二进制表达式的无效操作数"?
- 没有变量声明为函数,但错误:二进制表达式的操作数无效
- 如何修复此错误:二进制表达式的操作数无效("std::vector<double>"和"double")?
- 如何将无效操作数修复为二进制表达式
- 错误:二进制表达式的操作数无效(映射使用查找函数错误)
- 错误:二进制表达式('float' 和 'float')返回的无效操作数 (x & (1 << 31)) == 0
- 对条件表达式结果的赋值(其中第二个和第三个操作数是相同类型和值类别的变量)是否仍然存在?
- 如何将无效操作数修复为带有字符串的二进制表达式?
- 实现 vector 时二进制表达式的操作数无效
- 提升multi_index示例:错误:二进制表达式的操作数无效
- 无效的操作数到二进制表达式:
- 为什么在未评估的操作数中不允许使用lambda表达式,而是允许在恒定表达式的未评估部分中
- 二进制表达式的操作数无效("无线电设备"和"常量无线电设备")
- “无效的操作数是二进制表达式”当使用自定义结构作为C 中的MAP索引时
- 使用 std::replace C++ 时二进制表达式的操作数无效
- 二进制表达式的语义问题无效操作数("双精度"和"双精度")