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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T11:28:02+00:00 2026-06-18T11:28:02+00:00

The question may be hard to understand but the problem is quite simple and

  • 0

The question may be hard to understand but the problem is quite simple and I will describe it here in simple words.
Right now, my resource managment is:

    cResMgr<cTexture> textures;
    cResMgr<cSound> sounds;

What I want to do is:

    cResMgr resources;
    resources.add<cTexture>(...);
    resources.get<cSound>(...);

Basically, my resource manager has “get” and “add” functions. I want it that when I call function for cWhatever type first time, it creates a container for it. When it is called for the next times, it is just is there (it’s similar to static variable in function)

The question is, how can I implement it? The only solution I can think of is to have every resource deriving from empty base class cResource, so that way I can have one container of pointers to cResource. The problem is, that the resource types aren’t mine (they are from external lib)

Any solutions?

  • 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-18T11:28:03+00:00Added an answer on June 18, 2026 at 11:28 am

    I don’t really know why you wouldn’t just use different resourcemanagers per resource type.

    Also, if it’s okay for the collections to be globally static, why do you need an instance of a resource manager?

    Anyways, this should do what you describe:

    #include <string>
    #include <map>
    
    typedef double cTexture;
    typedef std::string cSound;
    
    struct cResMgr
    {
        template <typename T>
            void add(std::string const& id, T const& v) const
            {
                mapFor<T>()[id] = v;
            }
    
        template <typename T>
            T& get(std::string const& id) const
            {
                return mapFor<T>().at(id);
            }
    
        private:
        template <typename T>
        static std::map<std::string, T> mapFor()
        {
            static std::map<std::string, T> _theMap;
            return _theMap;
        }
    };
    
    int main()
    {
        cResMgr resources;
        resources.add<cTexture>("wall", cTexture {});
        resources.get<cSound>("sad_trombone");
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My question may be quite similar to others, but not the same. In the
The question may be a little vague but here's an example of what I
This question may sound cliched, but I am in a situation here. I am
This question will use scikits.cuda [1] in the Python command line, but may equivalently
This is hard to explain but if you go here: https://developers.facebook.com/docs/reference/api/ You will see
I understand that this question may seem somewhat ungrounded, but if someone knows anything
I hate to ask what may be a simple question, but I'm still new
Ok, I know the title is quite complicated but the question is hard to
Well this question may seem odd but it's simple - my point is if
I may be asking the wrong question here so I will provide a small

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.