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 8073641
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T14:23:43+00:00 2026-06-05T14:23:43+00:00

I have a vector, which contains a class object. I declared like this vector<Aircraft>

  • 0

I have a vector, which contains a class object.
I declared like this

vector<Aircraft> queue;

I erase the first element in the vector. But it seems like the first element still in the vector. I did this.

queue.erase(queue->begin());
cout<<queue.size(); //printed 0 
Aircraft temp = queue.front();
cout<<temp.id; //expected a segfault error

The size of the vector is 0 after I erased the first element (there was only one element).
I was expecting a seg fault error when I tried to see the id of temp (Aircraft) since I erased the first element from the vector and the size is zero after that.
I even cleared the vector but ‘queue.front‘ still returns the object and cout statement still prints the id of the object.

  • 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-06-05T14:23:45+00:00Added an answer on June 5, 2026 at 2:23 pm

    It’s undefined behavior to access the front() of a vector that is empty so you must not do it and you can’t infer anything from the apparent behavior of your program if you do do it.

    The fact that queue.size() is one less than before the .erase call should tell you that erase has worked.

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

Sidebar

Related Questions

I have a vector-like class that contains an array of objects of type T
I have a map class, which contains a vector containing MapEntitys. MapEntity is a
I have a string vector which contains html tags e.g abc<-welcome <span class=\r\><a href=\abc\>abc</a></span>
So I have a container(any kind, probably std::map or std::vector) which contains objects of
I have a vector of pairs representing hops between nodes which I would like
I have a class which has a private attribute vector rectVec; class A {
I have a class that has a vector member variable, which I fill up
I have a custom Vector class that contains an x, y, and z. These
I have a vector declared as: vector<Curve> workingSet; Curve is a class I've created
I have an (access) database table which contains data I would like to populate

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.