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

Ask A Question

Stats

  • Questions 92k
  • Answers 92k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I suspect you need bool operator<(const Foo& foo1) const; Note… May 11, 2026 at 6:27 pm
  • Editorial Team
    Editorial Team added an answer If you leave console.log() calls in your production code, then… May 11, 2026 at 6:27 pm
  • Editorial Team
    Editorial Team added an answer You might have cua-mode enabled as well which has similar… May 11, 2026 at 6:27 pm

Related Questions

I use Assert.Fail a lot when doing TDD. I'm usually working on one test
I ended up with something like the following code in a project I'm working
I'm using C#, .NET 3.5. I understand how to utilize events, how to declare
I was wondering what exactly is the difference between MVC(which is an architectural pattern)
I believe I'm getting bitten by some combination of nested scoping rules and list

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.