   problem with stl sort
  gidday im getting an error with the following code all the numbers are > 0 && < 300 ( confirmed but the cout )but when i do the sort function the error is triggered sometimes (0.01% of cases) because one of the numbers has become less than 0 inline bool sort_func( int a, int b ){if ( a < 0 || b < 0 )cout << "ERROR" << a << " " << b << endl;}copy ( V.begin(), V.end(), ostream_iterator<int> ( cout, " " ) );cout << endl;sort( V.begin(), V.end(), sort_func );---------------------------btw no improvement withstruct other_one  : public binary_function<int, int, bool> {bool operator()(int a, int b) { if ( a < 0 || b < 0 )cout << "ERROR" << a << " " << b << endl;}};ta zed   
  What type of objects are in V? And why not post the proper code for your sorting function?   ;  If it happens so infrequently, then perhaps a stray pointer in another thread is being written to, corrupting your array, and likely causing other random errors or crashes.Which compiler and which STL implementation?Are you really sorting just integers, or are you sorting some class containing integer keys?Can you post more code?   ;  V is just plain ints ievector<int> V;they just id's to classes. i used to overload operator < for the sorting but now i need multiple sorting methods.so i take it im doing nothing wrong (in this part) and the problem lies elsewhere ( memory corruption, great i havent had one of those for years, gonna be fun :) )btw im using gcc 3.4.4thanks guys   ;  You're sort functions as you've posted them won't even compile (neither of them return a value), so as Kylotan said.....Quote:why not post the proper code for your sorting function?Also, do you have other threads operating on the data?  If so they could be corrupting things as iMalc suggested, but if not and your calls to std::copy and std::sort are as you've shown then the std::copy should also be showing the corruption.   ;  inline bool sort_func( int a, int b ){if ( a < 0 || b < 0 )cout << "ERROR" << a << " " << b << endl;MMM *mmmA = mmmLIB.return_MMM_ptr_from_ID( a );CHECK_NULL_PTR( mmmA )MMM *mmmB = mmmLIB.return_MMM_ptr_from_ID( b );CHECK_NULL_PTR( mmmB )return mmmB->valA < mmmA->valA;}Quote:but if not and your calls to std::copy and std::sort are as you've shown then the std::copy should also be showing the corruption.the strange thing is if i do the following it prints out values that are all greater than 0inline bool sort_func( int a, int b ){if ( a < 0 || b < 0 ){ cout << "ERROR" << a << " " << b << endl; copy ( V.begin(), V.end(), ostream_iterator<int> ( cout, " " ) );}}zed   ;  i like your naming convention [grin]i'd say the problem is somewhere in this function:MMM *mmmLIB::return_MMM_ptr_from_ID( int );i think everyone thought your vector of ints was being sorted by the int value, not some kind of crazy map object.your vector, V doesnt give us any clues as to what it contains.   ;  quick note to lets yous know not to give it any more thoughtim onto the path of solving it, its memory getting corrupted elsewhere (i was aware of the error a couple of months ago and placed it on the TODO list, but so little time, yada yada :) )im no expert in stl (only been using it for the last year) which is why i posted to see if i was using the sort function correctly, i still find this very strange thoughinline bool sort_func( int a, int b ){if ( a < 0 || b < 0 ){cout << "ERROR" << a << " " << b << endl;copy ( V.begin(), V.end(), ostream_iterator<int> ( cout, " " ) );}}Quote:your vector, V doesnt give us any clues as to what it contains.V is a vector of int'sQuote:i like your naming conventionu aint seen nothing, my names often takeup half the pageeg in the function down i havevoid return_list_of_intersecting_mmmIDs_in_scene_in_CS_with_shadowMV( .. ){ normal_mmmIDs_in_shadowMV_container.begin() etc}   ;  save_a_lot_of_space, ByUsingCapitalLetters.  ;-)   ;Quote:Original post by zedzeekQuote:i like your naming conventionu aint seen nothing, my names often takeup half the pageeg in the function down i havevoid return_list_of_intersecting_mmmIDs_in_scene_in_CS_with_shadowMV( .. ){ normal_mmmIDs_in_shadowMV_container.begin() etc}[lol]That's not a name, that's a description![lol]Thank goodness for auto-complete eh.So hows the weather down south?[grin]   