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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:49:03+00:00 2026-05-27T04:49:03+00:00

I observed that in my program I needed to make several classes use the

  • 0

I observed that in my program I needed to make several classes use the following common pattern. The idea behind it is that resource_mgr maintains a list of reference-counted pointers to resource objects, and exclusively controls their lifetime. Clients may not create or delete resource instances, but may request them from resource_mgr.

class resource_impl
{
    public:
        // ...

    private:
        resource_impl(...);
        ~resource_impl();
        // ...
        friend class resource_mgr;
}

class resource_mgr
{
    public:
        // ...
        shared_ptr<resource_impl> new_resource(...);

    private:
        std::vector<shared_ptr<resource_impl> > resources_;
        static void delete_resource(resource* p); // for shared_ptr
}

How can I (or can I?) define a template to capture this common behavior?
The following illustrates how this template might be used:

class texture_data
{
    // texture-specific stuff
}

typedef resource_impl<texture_data> texture_impl;
// this makes texture_impl have private *tors and friend resource_mgr<texture_impl>

typedef resource_mgr<texture_impl> texture_mgr;

//...

texture_mgr tmgr;
shared_ptr<texture_impl> texture = tmgr.new_resource(...);

Update: Various instantiations of resource_impl should all have in common the following properties:

  • They have private constructors and destructor
  • Their “associated” resource_mgr (the manager class that manages the same type of resource) is a friend class (so it can create/destroy instances)
  • 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-27T04:49:04+00:00Added an answer on May 27, 2026 at 4:49 am

    First add the interface :

    class resource_interface
    {
      public:
        virtual ~resource_interface() = 0;
        virtual void foo() = 0;
    };
    

    Then change the resource_impl into template :

    template< typename T >
    class resource_impl : public T
    {
        public:
            // ...
    
        private:
            resource_impl(...);
            ~resource_impl();
            // ...
            friend template< typename > class resource_mgr;
    }
    

    Then change resource_mgr into template:

    template< typename T >
    class resource_mgr
    {
        public:
            // ...
            shared_ptr<T> new_resource(...);
    
        private:
            std::vector<shared_ptr<T> > resources_;
            static void delete_resource(T* p); // for shared_ptr
    }
    

    And you should have very generic resource_impl and resource_mgr classes.

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

Sidebar

Related Questions

I want to make a program that does an order entry system for beverages.
I debugged the program and observed that it is stopped when it wants to
I have observed that, very infrequently, Internet Explorer (7 or 8, it does not
Making UML sequence diagram in VS 2010RC I've observed that there is no activation
With a third party API I observed the following. Instead of using, public static
This is a common question, but the explanations found so far and observed behaviour
I'm working on a program that needs to edit some objects in an Access
I have a small test program that creates millions of files (for testing purposes)
My co-workers are using a commercial program that encodes and stores login passwords on
Of late, I'm becoming more health oriented when constructing my program, I have observed

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.