Why is my vector code approved? What is a statement?

What is "assert", or rather, how can I get rid of an error. When I create a vector of pointers to a class with an int x data element, and then do this:

for(I=antiviral_data.begin();I<antiviral_data.end();I++)
{
    if((*I)->x>maxx)
    {
        antiviral_data.erase(I);
    }
}

And run the program, I don't get errors until x is greater than maxx, and I use .erase (), after which I get this error:

Failed to run debug check!

Program: ... My documents \ O.exe File: ... include \ vector Line: 116

Expression: ("This is → _ Has_container ()", 0)

For information on how your program can lead to an approval error, see the Visual C ++ documentation claims.

(Click Retry to debug the application)

[Abort] [Retry] [Ignore]

Also, if I try to use cout:

cout<<(*antiviral_data.begin())->x<<endl;

I get this error:

Failed to run debug check!

:... \O.exe :... include\vector : 98

: deferencable

, , . Visual ++ .

( "", )

[] [Retry] [Ignore]

-, , , ?

: antiviral_data - :

antiviral_data.push_back(new aX1(player.x,player.y,'>'));

.

+3
4

, , , . :

for(I=antiviral_data.begin();I!=antiviral_data.end();)
{
    if((*I)->x>maxx) I=antiviral_data.erase(I); else ++I;
}

. http://www.cppreference.com/wiki/stl/vector/erase, .

+11

, , , - " " , .

, , , - . , , . , , - .

( Visual ++, ). , , , , .

- Vector (), 98, , . , , . , .

, , , , , , .

+7

erase. . . remove_if. - " STL". .

+1

, . STL .

namespace {
   struct exceeds : public std::unary_function< TheUnknownType*, bool >
   {
      exceeds_max( int max ) : maxx( max ) {}
      bool operator()( TheUnknownType* data ) {
         return data->x < max;
      } 
   private:
      int maxx;
   };
}
void your_function()
{
   std::vector< TheUnknownType* >::iterator new_end;
   new_end = std::remove_if( antiviral_data.begin(), antiviral_data.end(), exceeds(maxx) );
   antiviral_data.remove( new_end, antiviral_data.end() );
}

, . . , , ... STL remove_if , , . std::vector < > :: remove, .

0

Source: https://habr.com/ru/post/1707556/


All Articles