c++ - array iterator not dereferencable error -


there sample code occurs error bellows. in release mode, works , prints 5 '-'. however, in debug mode, doesn't work , occurs runtime error 'array iterator not dereferencable'.

environment details : windows 7 64bit visual studio 2015 update 2

i don't know why there deferences between release , debug mode. in advance.

#include <iostream> #include <array>  static bool operator != (int * a, std::array<int, 5>::iterator &b) {     return != &(*b); }  int main(void) {     std::array<int, 5> arr = { 0,0,0,0,0 };      (auto* = &arr[0]; != arr.end(); it++)     {         std::cout << "-" << std::endl;     }      return 0; } 

you call *b when b arr.end(). causes undefined behaviour. can use * on iterator refers element of array.


Comments

Popular posts from this blog

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -