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

  • Home
  • SEARCH
  • 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 6747033
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:23:36+00:00 2026-05-26T12:23:36+00:00

I have a vector (order is important) of objects (lets call them myobj class)

  • 0

I have a vector (order is important) of objects (lets call them myobj class) where I’m trying to delete multiple objects at a time.

class vectorList
{

    vector<*myobj> myList; 
};

class myobj
{

    char* myName;
    int index;
    bool m_bMarkedDelete;
}

I was thinking that the best way to do this would be to mark specific myobj objects for deletion and then call myList.remove_if() on the vector. However, I’m not exactly sure how to use predicates and such for this. Should I create a member variable in the object which allows me to say that I want to delete the myobj and then create a predicate which checks to see if the member variable was set?

How do I implement the predicate as a part of the vectorList class?

  • 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-26T12:23:36+00:00Added an answer on May 26, 2026 at 12:23 pm

    Should I create a member variable in the object which allows me to say
    that I want to delete the myobj and then create a predicate which
    checks to see if the member variable was set?

    Haven’t you already done that? Isn’t that what m_bMarkedDelete is for? You would write the predicate like this:

    bool IsMarkedToDelete(const myobj & o)
    {
        return o.m_bMarkedDelete;
    }
    

    Then:

    myList.erase(
        std::remove_if(myList.begin(), myList.end(), IsMarkedToDelete),
        myList.end());
    

    Or, using lambdas:

    myList.erase(
        std::remove_if(myList.begin(), myList.end(),
            [](const myobj & o) { return o.m_bMarkedDelete; }),
        myList.end());
    

    If your class doesn’t actually have that member, and you’re asking us if it should, then I would say no. What criteria did you use to decide to mark it for deletion? Use that same criteria in your predicate, for example:

    bool IndexGreaterThanTen(const myobj & o)
    {
        return o.index > 10;
    }
    

    note — The functions I’ve written are of course invalid since all your members are private. So you’ll need some way to access them.

    • 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 vector of pointers to a class. I need to call their
in clojure i have vector [myfn1 myfn2 myfn3] how can i call functions named
Here is my issue, lets say I have a std::vector with ints in it.
I'm trying to sort a vector of objects using a predicate function and I'm
I have vector data for buildings on my map and want them to appear
For simplicity lets assume that I have a vector of N matrices each of
i want to parse a $_files vector in order to make a multiple upload.
I have a vector of Student objects which I want to sort using #include
Say you have a vector class that has a template length and type -

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.