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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:51:45+00:00 2026-06-13T08:51:45+00:00

I have a question related to boost::shared_ptr<> in C++. I am currently willing to

  • 0

I have a question related to boost::shared_ptr<> in C++. I am currently willing to perform a smart deletion of the items of my list:

  • If the item is in use, don’t do anything, and delete it later
  • If the item is not in use, delete it

This is a behavior required by my program.

I am really wondering how to do that properly since the std::list<boost::shared_ptr<object> > remove/erase functions causes the deletion of the shared_ptr<> and therefore of the real object.

So I finally came up with this solution: use a std::list<object*> and inherit object from boost::enable_shared_from_this<>. That way, when someone needs to use an item from the list, I give them object->shared_from_this().

My questions are the following:

  • Would this respect the desired behavior ?
  • Does the boost::shared_ptr<> associated to shared_from_this() takes into consideration the reference to the object in the list ?

I hope my question is explicit enough and that someone will be able to help me. The proper use of the smart pointers in lists is something I’d like to be able to use.

Thank you

  • 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-13T08:51:46+00:00Added an answer on June 13, 2026 at 8:51 am

    When you delete a shared_ptr you don’t delete the real object unless it is not used anywhere else. That’s the whole point about using shared_ptr.

    For instance, if you take one element of the list, copy it and give it to another function, then delete the element from the list, the real object won’t be deleted because it is still referenced somewhere else.

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

Sidebar

Related Questions

I have a question related to this one . I don't want to do
Another question related to this one . I have a List<SortableObjects> that is the
I have question related to what is done in SMS application is if i'm
I have a question related to this one : I'm trying to attach an
I have a question related to understanding of how python dictionaries work. I remember
I have following event class. I have a question related to the Property method
I have a modeling question related to profiles. Firstly, I have looked into using
I have multiple websites run on single database. My question related table Structure is
This question is related to database/RDBMS where i have little knowledge regarding performance and
I have read other related question but i cant really get them to relate

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.