vector iterator not dereferencable at runtime on a vector<vector<vector<A*>*>*>

Posted by marouanebj on Stack Overflow See other posts from Stack Overflow or by marouanebj
Published on 2010-05-07T09:24:14Z Indexed on 2010/05/07 9:28 UTC
Read the original article Hit count: 553

Filed under:
|
|
|

Hi,

I have this destructor that create error at runtime "vector iterator not dereferencable".

The gridMatrix is a std::vector<std::vector<std::vector<AtomsCell< Atom<T> * > * > * > * >

I added the typename and also the typedef but I still have the error.

I will move for this idea of vect of vect* of vect* to use boost::multi_array I think, but still I want to understand were this is wrong.

/// @brief destructor
~AtomsGrid(void) {
  // free all the memory for all the pointers inside gridMatrix (all except the  Atom<T>* )
  //typedef typename ::value_type value_type;

  typedef std::vector<AtomsCell< Atom<T>* >*> std_vectorOfAtomsCell;
  typedef std::vector<std_vectorOfAtomsCell*> std_vectorOfVectorOfAtomsCell;

  std_vectorOfAtomsCell* vectorOfAtomsCell;
  std_vectorOfVectorOfAtomsCell* vectorOfVecOfAtomsCell;
  typename std_vectorOfVectorOfAtomsCell::iterator itSecond;
  typename std_vectorOfVectorOfAtomsCell::reverse_iterator reverseItSecond;
  typename std::vector<std_vectorOfVectorOfAtomsCell*>::iterator itFirst;


  //typename std::vector<AtomsCell< Atom<T>* >*>* vectorOfAtomsCell;
  //typename std::vector<std::vector<AtomsCell< Atom<T>* >*>*>* vectorOfVecOfAtomsCell;
  //typename std::vector<std::vector<AtomsCell< Atom<T>* >*>*>::iterator itSecond;
  //typename std::vector<std::vector<AtomsCell< Atom<T>* >*>*>::reverse_iterator reverseItSecond;
  //typename std::vector<std::vector<std::vector<AtomsCell< Atom<T>* >*>*>*>::iterator itFirst;


  for (itFirst = gridMatrix.begin(); itFirst != gridMatrix.end(); ++itFirst) {
    vectorOfVecOfAtomsCell = (*itFirst);
    while (!vectorOfVecOfAtomsCell->empty()) {
      reverseItSecond = vectorOfVecOfAtomsCell->rbegin();
      itSecond = vectorOfVecOfAtomsCell->rbegin().base();

      vectorOfAtomsCell = (*itSecond); // ERROR during run: "vector iterator not dereferencable"
      // I think the ERROR is because I need some typedef typename or template ???!!!
      // the error seems here event at itFirst

      //fr_Myit_Utils::vectorElementDeleter(*vectorOfAtomsCell);
      //vectorOfVecOfAtomsCell->pop_back();
    }
  }
  fr_Myit_Utils::vectorElementDeleter(gridMatrix);
}

If someone want the full code that create the error I'm happy to give it but I do not think we can attach file in the forum. BUT still its is not very big so if you want it I can copy past it here.

Thanks

© Stack Overflow or respective owner

Related posts about stl

Related posts about container