我在我的类中定义了一个 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;
using namespace ::boost::multi_index;
struct RoadNetwork{
int n;
int m;
RoadNetwork(int q = 0,int p = 0){ n = q; m = p;};
};
class A
{
public:
typedef multi_index_container<
RoadNetwork,
indexed_by<
ordered_unique<identity<RoadNetwork> >,
ordered_non_unique<member<RoadNetwork, int, &RoadNetwork::n> >
>
> mindex;
mindex i;
const mindex::nth_index<0>::type& iterator_begin() const
{
return i.get<0>().begin();
}
};
int main(void){
A a;
return 0;
}
错误是:
~/workspace/multiIndex$ g++ main.cpp main.cpp: In member function ‘const type& A::iterator_begin() const’: main.cpp:30:34: error: invalid initialization of reference of type ‘const type& {aka const boost::multi_index::detail::ordered_index<boost::multi_index::identity<RoadNetwork>, std::less<RoadNetwork>, boost::multi_index::detail::nth_layer<1, RoadNetwork, boost::multi_index::indexed_by<boost::multi_index::ordered_unique<boost::multi_index::identity<RoadNetwork>
>,
boost::multi_index::ordered_non_unique<boost::multi_index::member<RoadNetwork, int, &RoadNetwork::n> > >, std::allocator<RoadNetwork> >, boost::mpl::vector0<mpl_::na>, boost::multi_index::detail::ordered_unique_tag>&}’ from expression of type ‘boost::multi_index::detail::ordered_index<boost::multi_index::identity<RoadNetwork>,
std::less<RoadNetwork>, boost::multi_index::detail::nth_layer<1, RoadNetwork, boost::multi_index::indexed_by<boost::multi_index::ordered_unique<boost::multi_index::identity<RoadNetwork>
>,
boost::multi_index::ordered_non_unique<boost::multi_index::member<RoadNetwork, int, &RoadNetwork::n> > >, std::allocator<RoadNetwork> >, boost::mpl::vector0<mpl_::na>, boost::multi_index::detail::ordered_unique_tag>::const_iterator {aka
boost::multi_index::detail::bidir_node_iterator<boost::multi_index::detail::ordered_index_node<boost::multi_index::detail::ordered_index_node<boost::multi_index::detail::index_node_base<RoadNetwork, std::allocator<RoadNetwork> > > > >}’
我重视你的帮助。
谢谢和问候