Why do I get this Debug Assertion Failed? Expression: list iterator not dereferenceable [migrated]
- by Karel
I'm trying this example in the (translated to dutch) book of Bjarne Stroustrup (C++):
#include <vector>
#include <list>
#include "complex.h"
complex ac[200];
std::vector<complex> vc;
std::list<complex> l;
template<class In, class Out> void Copy(In from, In too_far, Out to) {
while(from != too_far) {
*to = *from;
++to;
++from;
}
}
void g(std::vector<complex>& vc , std::list<complex>& lc) {
Copy(&ac[0], &ac[200], lc.begin()); // generates debug error
Copy(lc.begin(), lc.end(), vc.begin()); // also generates debug error
}
void f() {
ac[0] = complex(10,20);
g(vc, l);
}
int main () {
f();
}
** Compiling and Linking goes successful (0 errors/warnings)**
But at runtime I get this error:
Debug Assertion Failed!
Program: path to exe
file: \program files\ms vs studio 10.0\vc\include\list
Line: 207
Expression: list iterator not dereferenceable
For information on how your program can cause an assertion failure, see the Visual C++ documentation on asserts.
(Press retry to debug the application)