C++ 在Boost多索引容器中,在等_范围内移动时迭代器失败

C++ 在Boost多索引容器中,在等_范围内移动时迭代器失败,c++,boost,iterator,C++,Boost,Iterator,我在迭代器上犯了一些错误,但我还看不到 我有一个Boost多索引容器,HostContainer hmap,它的元素是Boost::shared\u ptr给类Host的成员。所有索引都作用于类宿主的成员函数。第三个索引是通过Host::gethouse(),其中house成员变量是一个int 下面,我尝试遍历匹配特定家庭的主机范围(int hhold2),并将相应的私有成员变量Host::id加载到数组中。当家庭规模为2时,我在运行时遇到“断言失败:(px!=0)、函数运算符->、文件/应用程

我在迭代器上犯了一些错误,但我还看不到

我有一个Boost多索引容器,
HostContainer hmap
,它的元素是
Boost::shared\u ptr
给类
Host
的成员。所有索引都作用于类宿主的成员函数。第三个索引是通过
Host::gethouse()
,其中
house
成员变量是一个
int

下面,我尝试遍历匹配特定家庭的主机范围(
int hhold2
),并将相应的私有成员变量
Host::id
加载到数组中。当家庭规模为2时,我在运行时遇到“断言失败:(px!=0)、函数运算符->、文件/应用程序/boost_1_42_0/boost/smart_ptr/shared_ptr.hpp,第418行”错误。(我还不知道这是否会在家庭规模为2的任何时候发生,或者是否必须满足其他条件。)

typedef多索引容器<
boost::shared_ptr,
索引由
hashed_unique,//0-ID索引
有序非唯一,//1-年龄索引
有序非唯一/2-家庭索引
>//结束索引由
>主机集装箱;
typedef HostContainer::nth_index::type HostsByHH;
//内干管()
int numFamily=hmap.get().count(hhold2);
int familyIDs[numFamily];
for(int f=0;fpit=hmap.get().equal_range(hhold2);

哇,谢谢你指出这一点。它惊人地使用GCC4.2.1编译。我不明白为什么。@Sarah,显然,它编译是因为gcc有一个扩展,让这种语法(因为这种语法在C中是允许的)哇,谢谢你指出这一点。它惊人地使用GCC4.2.1编译。我不明白为什么。@Sarah,显然,它编译是因为gcc有一个扩展,允许这种语法(因为这种语法在C中是允许的)
typedef multi_index_container<
  boost::shared_ptr< Host >,
  indexed_by< 
    hashed_unique< const_mem_fun<Host,int,&Host::getID> >, // 0 - ID index
    ordered_non_unique< const_mem_fun<Host,int,&Host::getAgeInY> >, // 1 - Age index
    ordered_non_unique< const_mem_fun<Host,int,&Host::getHousehold> > // 2 - Household index
    > // end indexed_by
  > HostContainer; 

typedef HostContainer::nth_index<2>::type HostsByHH;

// inside main()
int numFamily = hmap.get<2>().count( hhold2 );
int familyIDs[ numFamily ];
for ( int f = 0; f < numFamily; f++ ) {
  familyIDs[ f ] = 0;
}
int indID = 0;
int f = 0;
std::pair< HostsByHH::iterator, HostsByHH::iterator > pit = hmap.get<2>().equal_range( hhold2 );
cout << "\tNeed to update households of " << numFamily << " family members (including self) of host ID " << hid2 << endl;
while ( pit.first != pit.second ) {
   cout << "Pointing at new family member still in hhold " << (*(pit.first))->getHousehold() << "; " ;
  indID = (*(pit.first) )->getID();
  familyIDs[ f ] = indID;
  pit.first++;
  f++;
} 
for ( HostsByHH::iterator fit = pit.first; fit != pit.second; fit++ ) {
  cout << "Pointing at new family member still in hhold " << (*fit)->getHousehold() << "; " ;
  indID = (*fit )->getID();
  cout << "id=" << indID << endl;
  familyIDs[ f ] = indID;
  f++;
} 
int numFamily = hmap.get<2>().count( hhold2 );
int familyIDs[ numFamily ];
int *familyIDs= new int[ numFamily ];