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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T15:53:31+00:00 2026-05-14T15:53:31+00:00

Would it be smart to have a vector in an object with a list

  • 0

Would it be smart to have a vector in an object with a list of pointers that point to it?

This way when the object is deleted, it could delete all the pointers pointing to it to prevent a null-pointer exception?

  • 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-14T15:53:31+00:00Added an answer on May 14, 2026 at 3:53 pm

    If your ultimate goal is to detect when an object is freed from users of the object the best bet is to use a weak pointer semantic. There an implementation in the Boost Smart Pointer library (see weak_ptr). It solves the problem you describe by reversing the reference graph you describe. It has the pointers reference a single common counter instance which when the originator deletes the object it sets to zero. Hence because all the weak_ptr references point to the single counter they all see the change immediately and hence you can tell when the object goes away.

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

Sidebar

Related Questions

I have a 3D vector defined like this... std::vector<std::vector<std::list<Object*> > > m_objectTiles; I have
i have a gravity vector (0, -9.8) for a world and an object. this
I have a script that cycles (almost like a slideshow) through a Vector object
I have a vector of pointers to Machines: That is, vector<Machines*> m; I populate
I thought I would be smart and create member functions that accepted output iterators.
I was wondering if using Lightbox all over the site would be a smart
My program has this function: vector<itemPtr> Level::getItemsAt(const Point& pt) { vector<itemPtr> vect(items.size()); // copy
The benefits to having a vector of reference-counted smart pointers are many. I no
Please suppose I have a function that accepts a pointer as a parameter. This
I have the following data that looks like this for example: 34 foo 34

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.