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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T02:55:08+00:00 2026-06-07T02:55:08+00:00

I wish to use a smart pointer to an object that will be accessed

  • 0

I wish to use a smart pointer to an object that will be accessed by quite a few different objects. Therefore i don’t want to destruct it until all the pointers are released to it. The smart pointer will point to an object that instantiates a couple objects, which instantiate a couple objects, and so on, so that you can access all the individual System objects through this one pointer. However, let’s say that i create the smart pointer in main as std::shared_ptr<System> object(new System); and then let’s say i have another object that all other entities derive from which has a static std::shared_ptr that i set equal to object above. The static declaration means that it’s managed by the compiler and not on a per instance basis. So let’s say that all the objects that derive from the base class use this static pointer to access the System object. WHEN is this smart pointer destructed if ever? I need this pointer to be destructed before the one in main, who’s destruction should drop the reference count to 0, destroying the object pointed to by it. So my question is, when is a statically declared std::shared_ptr destructed in the scheme of things. Or even if a pointer were declared globally and used all over, when would this object be destructed?

the base class would look something like this:

class Base
{
public:
    static shared_ptr<System> m_System;
};

int main()
{
    std::shared_ptr<System> system(new System);
    Base::m_System = system;

    /*
        other stuff
    */ 
    return 0;
}

also another thing that someone could help me with, i’m not very good with const-ness, and i would like for that static pointer to be a constant that cannot be changed by the derived classes. But then if it’s const i can’t initialize it like i did in main, right? so how would i go about declaring it so that it is const, but i can still set it equal to a pointer initially like 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-06-07T02:55:09+00:00Added an answer on June 7, 2026 at 2:55 am

    We have 2 reference for object, so, when we exit from main function – we decrement reference counter and then destruction of static objects decrement reference counter, when reference counter will be equal to 0, our System object will be destroyed.

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

Sidebar

Related Questions

I want to use Calendar widget to help users select date. I wish use
The problem: I wish to use Postgres Schemas to separate the tables of different
I wish to use sp_start_job to start a job from within an insert trigger
I wish to use the method with the following signature: exec(String command, String[] envp,
I wish to use Spring MVC to provide a REST web service. However, running
I wish to use a COM dll in my C++ library. The way I
I wish to use the Translator classes of Zend framework in my app, but
I wish to use common CRC logic in a VB.NET or C# application as
I wish to use JSON.Net on a brand spankin new Mono class library (say
I wish to use a jQuery .load(oracle apex url) query. I have a main

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.