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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T01:31:37+00:00 2026-06-12T01:31:37+00:00

I have a vector of Car objects, declared as vector<Car> vCars In one of

  • 0

I have a vector of Car objects, declared as

vector<Car> vCars

In one of my functions, I need to erase the first element of the vector. Sounds simple enough right? The line that is throwing the error:

vCars.erase( vCars.begin() );

And the error:

no matching function for call to 'std::vector<Car>::erase(std::vector<Car>::const_iterator) const'

I understand erase generally only takes an iterator for its parameter, and not a const_iterator. I’ve been looking for solutions or workarounds to the error, such as the erase-remove idiom, but from what I’m seeing, that only removes an element by value, when I need to be removing by position – and simply enough, just the element at the first position! (I know this is not good performance wise for a vector, but I am required to use a vector for this)

edit: To clarify the situation, the function the call is contained within is below:

    /// Removes the Car at the front of the garage without returning the instance.
    void Garage::pop() const {
        if ( !empty() ) {
          vCars.erase( vCars.begin() );
        }
    }

edit: And I now see where I went wrong. There were a lot of methods that were const and I just mindlessly made pop() a const method! Once I removed const, the problem was resolved. Thanks for pointing me in the right direction!

  • 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-12T01:31:38+00:00Added an answer on June 12, 2026 at 1:31 am

    The error message:

    no matching function for call to ‘std::vector::erase(std::vector::const_iterator) const’

    implies that vCars.begin() yields a const_iterator, which in turn implies that vCars is a constant object or reference. You are not allowed to modify the vector through that reference. If the function needs to modify the vector, it cannot take a constant reference.

    Note that in a member function declared as const the implicit this pointer is of type T const * (i.e. you cannot modify the object inside a const function). If this is your case, you will need to drop the const qualifier from the function.

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

Sidebar

Related Questions

in clojure i have vector [myfn1 myfn2 myfn3] how can i call functions named
I have a vector of objects (objects are term nodes that amongst other fields
I have a vector where I keep an incrementing data. Normally each element of
I have Vector declared in index.jsp page like this: <%! Vector vNumbers = new
I have a vector and it is going to hold 10 objects maximum. When
Consider this: I have vector fav.activities with names of the objects: fav.activities <- c(swiming,
I have 2 vector of with one has vec1{e1,e2,e3,e4} and the other one with
If I have vector<T> list Where each element in the list is unique, what's
How does one determine what the differences of 2 vectors are? I have vector<int>
I have vector<unsigned char> filed with binary data. I need to take, lets say,

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.