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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T22:40:30+00:00 2026-06-11T22:40:30+00:00

I ran into a problem with a dirty shutdown of my program, because of

  • 0

I ran into a problem with a dirty shutdown of my program, because of a shared pointer. I found a solution, but I’m not sure, if I have the right answer.

This is the minimalistic example:

double var;
boost::shared_ptr<const double> ptr1 (&var); // creates an invalid pointer on program exit
boost::shared_ptr<const double> ptr2 (new double); // works fine

int main (int argc, char **argv)
{
  return 0;
}

Here is my answer which I would like to varify:

In the case of ptr1 the pointed-to object will be deleted before the pointer, which then points to an invalid address. But in the case of ptr2 the “smartness” of the shared pointer handles the issue above.
True?

Small extra question:
Is there a way to make ptr1 work (I tried reset()) or is that bad programming practice (if so why)?

Thanks for the clarification!

  • 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-11T22:40:32+00:00Added an answer on June 11, 2026 at 10:40 pm

    in the first case, the pointer isn’t dynamically allocated, so the shared_ptr should not attempt to destroy the underlying object. that can be done by using a custom no-op deleter functor:

    http://www.boost.org/doc/libs/1_51_0/libs/smart_ptr/sp_techniques.html#static

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

Sidebar

Related Questions

I ran into this problem earlier but I didn't ask it because I found
Similar to my last question, but I ran into problem lets say I have
I ran into this problem in a Visual Basic program that uses WMI but
Never ran into this problem with jQuery before. I have the following: $(document).ready(function() {
I ran into a problem today at work wherein I have a BindingGroup that
Ran into a problem. I have a spawned thread that must call its finally
I ran into the problem where in Silverlight event MouseLeftButtonDown is not being fired
I ran into a problem.I'm doing a GIS program using flex. There's a map
I ran into such problem: I have one header file: //first variant: #ifndef LIBRARIES_H
I ran into the problem in Java, but I guess it's a question about

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.