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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:06:36+00:00 2026-05-26T22:06:36+00:00

I have a resource_manager class which maintains a std::vector<boost::shared_ptr<resource> > internally. resource_manager is a

  • 0

I have a resource_manager class which maintains a std::vector<boost::shared_ptr<resource> > internally. resource_manager is a friend class of resource. I want resources to only be created/deleted by resource_manager, so I made its constructors private (which works ok).

However, if I make the destructor private, the code doesn’t compile because the destructor is called by boost::shared_ptr, which is not a friend of resource. I am thinking of enforcing the “do not delete by clients” rule by only returning only const resource* from the resource_manager, but somehow I am not satisfied with the security this method provides (what if a client somehow happens across a pointer to non-const?)

Apart from the obvious solution of not using shared_ptr, do you have any workaround / better solution to my problem?

  • 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-26T22:06:36+00:00Added an answer on May 26, 2026 at 10:06 pm

    You can pass a custom deleter to the shared pointer. So just create a deleter functor or function (up to you) which in turn is a friend of your class:

    class Secret
    {
      ~Secret() { }
      friend class SecretDeleter;
      friend void SecretDelFunc(Secret *);
    };
    
    class SecretDeleter
    {
    public:
      void operator()(Secret * p) { delete p; }
    };
    
    void SecretDelFunc(Secret * p) { delete p; }
    
    std::shared_ptr<Secret> sp1(new Secret, SecretDeleter());
    std::shared_ptr<Secret> sp2(new Secret, SecretDelFunc);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an EXE class which contains a button resource with ID EXE_BUTTON_RESOURCE ON_UPDATE_COMMAND_UI(EXE_BUTTON_RESOURCE,
I'm working on a resource management class and want to have the user provide
I have a static class in which one property defines a resource manager. for
I have a scenario in which I have REST API which manages a Resource
I have resource dictionary files (MenuTemplate.xaml, ButtonTemplate.xaml, etc) that I want to use in
We have a class which installs and configures OpenVPN. However, in order for the
We have a small wrapper class that uses ResourceManager to load string resources from
I have an abstract base class that I use for services which includes the
I have a project which has multiple Resource (resx) files along with the accompanying
I have resource bundle with my country characters - how to change them into

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.