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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:27:37+00:00 2026-05-25T12:27:37+00:00

I am using boost::shared_ptr to organize my pointer data in my game engine. I

  • 0

I am using boost::shared_ptr to organize my pointer data in my game engine.

I tried to make a very short example to show my problem:

class CSceneNode
{
public:
    CSceneNode(CScene *p) : parent(p) {}

    void foo() {
        parent->notifyThatFooWasCalledOnMe(my_shared_ptr_version_of_this???);
    };

    CScene *parent;
};

class CScene
{
public:
    void addNode() {
        nodes.push_back(boost::shared_ptr<CSceneNode>(new CSceneNode(this)));
    }

    void notifyThatFooWasCalledOnMe(boost::shared_ptr<CSceneNode> node) {
        foo_was_called[node] = true;
    }

    std::list<boost::shared_ptr<CSceneNode> > nodes;
    std::map<boost::shared_ptr<CSceneNode>, bool> foo_was_called;
};

Thus the problem is:
CScene creates CSceneNode’s and owns these in boost::shared_ptr’s into a list.

Now the child needs to notify the parent of a change. This is easy, as I passed the pointer of CScene onto CSceneNode, the node knows its parent. As the node will not live longer than the parent, it is ok to just pass a pointer.

But the parent also needs to know who it is that calls it back, and there’s the problem. The parent doesn’t know the raw pointers, it only knows shared pointers, so the only way to find out which child is calling is searching over all nodes to find that one with the same raw pointer inside, or create another map mapping from raw pointer to shared_ptr. This last one then needs extra maintenance when a node is deleted. I could also pass the shared_ptr to the child itself to help it send itself back, but that seems stupid.

Can anyone tell me what to do? Is there a better way to do this?

  • 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-25T12:27:37+00:00Added an answer on May 25, 2026 at 12:27 pm

    Now the child needs to notify the parent of a change.

    Remove this requirement, and the whole problem collapses… as well as your cyclic dependency.

    You might consider an event-based system instead, or state polling.

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

Sidebar

Related Questions

Please consider the following simplified example: #include boost/shared_ptr.hpp #include boost/smart_ptr/enable_shared_from_this.hpp using namespace boost; class
I have a C++ RAII class for managing Win32 HANDLEs using boost::shared_ptr<> that looks
I have the following code: #include <iostream> #include boost/shared_ptr.hpp using boost::shared_ptr; class Base {
When using the pImpl idiom is it preferable to use a boost:shared_ptr instead of
How much do using smart pointers, particularly boost::shared_ptr cost more compared to bare pointers
I'm using boost's shared pointers, and enable_shared_from_this to enable returning a shared pointer to
I'm new in using boost and have a problem. I need shared_mutex function in
I have just started using Boost 1.36. These libraries would be very useful in
I think I'm missing something simple here. I'm using Boost's shared_ptr . shared_ptr<Foo> pA(new
I'm using Boost/shared_ptr pointers throughout my application. When the last reference to an object

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.