   vectors problem
  Hello everyone,I've been using vectors for some time now, i mostly use them the same way: declare one as a global variable that will hold some specific data, but this is the first time i ever get such errors at debugging, so here's what's happening:1- i define a global variable ( a vector of integers )2- call clear() or erase() methods3- get the error:debug assertion failed........Expression: vector iterators incompatible......What does this mean? i've always been using vectors the same way, when i create a new project, and use a vector in the same way, it works just fine, so what might cause this program specifically to cause this error, and not the other projects?note that this only happens when debuggingalso note that this is how i declare themvector<int> SelV;//starting pointvoid HasX ( hxCore* core ){//clear the vector ( anytime during the program, not necessarily at beginning ) SelV.clear ( );//failue....}[Edited by - Hassanbasil on May 18, 2010 7:50:05 AM]
  Also forgot to mention that it only fails when declaring it as a global variable, it works fine as a local one   ;  That error is probably the result from comparing iterators of two differentvectors. For example :std::vector<int> v(5,0);std::vector<int> y(5,0);if(v.begin() != y.end()){//error}Show more code, and we may be able to help.   ;  well actually there is no more code to show, if i only call clear() (or erase if i have elements), i get the error, i used the clear method at the beginning point of the program, and the program is crashing at starting point, so i believe any other code wont be requiredi also believe that it has something to do with global/local variable(s), although i'm using them without any problems (other than vectors), maybe it's worth to mention that this file does not include the main starting point, i have multiple files in the project, Main function is called from another file, and the Main function there calls HasX here ( which where my error is happening ), maybe there is something i have missed about global variables?here's how it looks like////main file that includes Main function//int APIENTRY hxMain ( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR cmdLine, int cmdShow ){srand ( timeGetTime ( ) );timeBeginPeriod ( 1 );hxCore* MAINCORE = new hxCore ( );HasX ( MAINCORE ); //CALL THE FUNCTION HEREMAINCORE->~hxCore ( );MAINCORE = NULL;timeEndPeriod ( 1 );exit ( 0 );return 0;}////the current file which im getting the error at//#include "HasX10.h"vector<int> SelV;void HasX ( hxCore* core ){SelV.clear ( );//crash.....So this simply crash at calling clear(), i dont really know what's wrong there   ;  Is HasX()being called before main()?If so, it sounds like you may be encountering a variation of the static initialization fiasco.   ;  @ Rattrap : no, it's called from main not before it, i edited the post above a few seconds after you posted, describing some more details   ;  If there isn't any more code that is relevant, can you make the relevant code into a minimal program that shows the problem? Post that so people can try to reproduce the problem.EDIT: For instance, does this program reproduce the problem? If it doesn't, it means you are doing something else that matters.#include <vector>std::vector<int> my_vector;int main() {  my_vector.clear();};  Why are you calling your destructor explicitly?   ;  Here's a little project that causes the issue:////main.h//#include <Windows.h>#include <vector>using std::vector;void ERRORFUNC ( void );////main.cpp//#include "main.h"int APIENTRY Main ( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR cmdLine, int cmdShow ){ERRORFUNC ( );return 0;}////error.cpp//#include "main.h"vector<int> intV;void ERRORFUNC ( void ){intV.clear ( );return;}that simply causes the error   ;Quote:Original post by HassanbasilHere's a little project that causes the issue:*** Source Snippet Removed ***that simply causes the errorWorks fine for me (after replacing Main with WinMain for it to be able to compile).