Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 202667
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T17:18:36+00:00 2026-05-11T17:18:36+00:00

What exactly is an assert, or more specifically, how do I get rid of

  • 0

What exactly is an “assert”, or more specifically, how do I get rid of an error. When I create a vector of pointers to a class with data member int x, 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 get no errors until x is greater than maxx and I use .erase(), at which point I get this error:

Debug Assertion Failed!

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

Expression:
(“this->_Has_container()”,0)

For information on how your program
can cause an assertion failure, see
the Visual C++ documentation on
asserts.

(Press 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:

Debug Assertion Failed!

Program: …My Documents\O.exe File:
…include\vector Line: 98

Expression: vector iterator not
deferencable

For information on how your program
can cause an assertion failure, see
the Visual C++ documentation on
asserts.

(Press Retry to debug the application)

[Abort][Retry][Ignore]

Could somebody please tell me why I can’t USE any of the data in the vector, and how to fix it?

ALSO: antiviral_data is a vector of pointers, with a single element:

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

If that helps.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T17:18:36+00:00Added an answer on May 11, 2026 at 5:18 pm

    The most probable reason why you get the assertion is that you increment I after an erase. Try this instead:

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

    See also http://www.cppreference.com/wiki/stl/vector/erase , search for invalid iterators on that page.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Exactly what the title says. I'm using MSVC++ 2008 express, and my class constructor
How exactly can I create a new directory using Emacs? What commands do I
Let's say I have 3 classes. I expect sizeof() each class to be exactly
I'm using NHibernate to persist this entity: public class Store { public int Id
What exactly is the difference between: scala> def foo = 5 foo: Int and
Why exactly do we need a Circular Linked List (singly or doubly) data structure?
Exactly what the title says. Note, this is not about subscriptable objects.
Exactly that: Does a strings length equal the byte size? Does it matter on
How exactly do DLL files work? There seems to be an awful lot of
What exactly is the difference between the window.onload event and the onload event of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.