【发布时间】:2018-02-16 18:49:10
【问题描述】:
我有一个结构
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;}
getId(){return id;}
getName(){return 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;
但是,如果我将员工结构的成员设为私有,那么我将无法使用 em 作为容器的键。我尝试将指针指向像 &emploeyy::getName 这样的 getter 函数,但它并没有解决问题。
所以我的问题是:如何使用私有成员作为多索引容器的键?
【问题讨论】:
-
你将如何将
employee的成员暴露给任何其他会使用它的东西? -
我可以添加setter-getter函数
标签: c++ boost boost-multi-index