Good day! I have a basic dialog-system and faced the problem of losing the pointer passed to the constructor.

I have a child class that calls the base constructor, passing the parameter further:

SceneTwo(shared_ptr<ContentManager>* manager) : GUIElement::GUIElement(manager) { } 

In the base class in the constructor, we initialize the required protected parameter for future access to it from the child classes.

 GUIElement::GUIElement(shared_ptr<ContentManager>* manager) { _contentManagerPtr = manager; _sceneContainer = _contentManagerPtr->get()->sceneContainer(); } 

And that's what's interesting - when debugging, at the time of entry into

 GUIElement::GUIElement(shared_ptr<ContentManager>* manager) 

manager - contains a pointer, but after 1 iteration, it throws me further by 3 steps in GUIElement.h, variables are inserted there and returned to the body of the constructor - the manager parameter is not correct ... http://prntscr.com/c082oc

  • one
    I think you need to put together a "minimal example that reproduces the problem" - KoVadim
  • 2
    You for some reason pass a smart pointer on the pointer. Thus, the assignment counter does not increase. Perhaps, then simply deleting an object that is controlled by shared_ptr - Pavel Parshin
  • I am sorry that I came here with such a delay) Probably, Pavel, you are right. I just have a basic manager that stores links to third-party modules. And I’m giving them a link by request, on purpose, so that the counter doesn’t increase and, with the destructiveness of the base manager, the entire application is beautifully closed (in general wisdom). But I give the link in this format return &static_pointer_cast<ManagerType> And it turns out when static_pointer_cast creates a copy and is it destroyed? - Roman Lipovskiy

0