c++ - std vector const_iterator assignment Access violation -
i'm working on code in 1 of more variable length object stored vector of units i.e. assuming each letter unit, , same letter same high level object. vector may contain following: aaaabbcccdeeffff...
this vector internal private variable of class has operator[] defined such vector above
- obj[0] returns const_iterator first "a" - obj[1] first "b" - obj[2] first "c" etc. const ai::genearray::const_iterator& ai::chromosome::operator[](int index) const { genearray::const_iterator pgene; int cindex; (cindex=0,pgene = this->vgenes.cbegin();pgene != this->vgenes.cend();pgene++, cindex++) { if (index == cindex) { break; } (*pgene)->endofblock(pgene); } return pgene; } then in function have following
ai::genearray::const_iterator function = vchromosome[0]; this causes access violation error.
the call stack's above function follows
ai.exe!std::_vector_const_iterator<std::_vector_val<ai::gene *,std::allocator<ai::gene *> > >::_vector_const_iterator<std::_vector_val<ai::gene *,std::allocator<ai::gene *> > >(const std::_vector_const_iterator<std::_vector_val<ai::gene *,std::allocator<ai::gene *> > > & __that) + 0x2f byte ai.exe!std::_iterator012<std::random_access_iterator_tag,ai::gene *,int,ai::gene * const *,ai::gene * const &,std::_iterator_base12>::_iterator012<std::random_access_iterator_tag,ai::gene *,int,ai::gene * const *,ai::gene * const &,std::_iterator_base12>(const std::_iterator012<std::random_access_iterator_tag,ai::gene *,int,ai::gene * const *,ai::gene * const &,std::_iterator_base12> & __that) + 0x2f bytes ai.exe!std::_iterator_base12::_iterator_base12(const std::_iterator_base12 & _right) line 118 ai.exe!std::_iterator_base12::operator=(const std::_iterator_base12 & _right) line 123 + 0x5 bytes the final call
_iterator_base12& operator=(const _iterator_base12& _right) { // assign iterator if (_myproxy != _right._myproxy) _adopt(_right._myproxy->_mycont);<- line return (*this); } according debugger (visual c++ 2010 express)
_right._myproxy-> _mycont = cxx0030: error: expression cannot evaluated _myfirstiter = cxx0030: error: expression cannot evaluated else in project have similar code using std::list, rather vector works correctly
parents = new chromosomelist::const_iterator[c]; *(parents) = --(this->vchromosomes.cend()); (int i=1;i<c;i++) { *(parents+i) = chromosomelist::const_iterator((*(parents+i-1))); (*(parents+i))--; } i've checked value returned by
vchromosome[0]
this value of correct type,
const ai::genearray::const_iterator & i've search google similar problems, i've been able find problem related looping through vector using iterator's
i.e.
for (ai::genearray::const_iterator pgene = genes.cbegin();pgene != genes.cend();pgene++) such code in project working correctly.
ai::genearray::const_iterator function = vchromosome[0]; should not compile. function iterator, you're attempting set value of contents of value. sure did not want vchromosome.begin() instead?
assuming that's typo here, bug not @ point assignment happens, bug somewhere before that. vchromosome might empty, example, in case attempting access operator[](0) lead undefined behavior. (see if vector valid first!)
(side note,
parents = new chromosomelist::const_iterator[c]; why managing array manually? isn't vector for? :) )
Comments
Post a Comment