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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T12:50:52+00:00 2026-06-09T12:50:52+00:00

Scenario is, I’m building a game with a TextureManager class that is responsible for

  • 0

Scenario is, I’m building a game with a TextureManager class that is responsible for loading and managing textures. Game objects implementing IVisibleGameObject will need a pointer/reference to a texture from the TextureManager.

Texture manager is implemented with a std::map<std::string, boost::shared_ptr<Texture> > to hold its objects internally.

I’m not certain how I should actually expose the textures, and thought of a few possibilities, each with their own downsides:

1) const Texture& GetTex(std::string textureKey)

I feel would be ideal, but I’d like to indicate that a texture was not found in the map by returning NULL. (Second guessing myself…IS this appropriate?)

2) shared_ptr<const Texture> GetTex(std::string textureKey)

Here I could return a null shared_ptr, but I’m uncomfortable with the implication it’s a shared object now. The TextureManager is the object’s owner, it’s the manager after all. However, considering the fact an IVisibleGameObject holds a reference/pointer to the returned Texture and depends on its existence to function correctly, isn’t it also an owner of the object, and maybe shared ownership is appropriate?

3) const Texture* GetTex(stD::string textureKey)

Obviously, this is the wrong answer.

Would love for someone to clear this up for me, perhaps there is something I haven’t considered.

  • 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-09T12:50:53+00:00Added an answer on June 9, 2026 at 12:50 pm

    I would stick with the standard library idiom and simply expose find and end. Then you can be perfectly efficient:

    auto it = my_objects.find("foo");
    
    if (it == my_objects.end())
    {
        // handle "not found"
    }
    else
    {
        it->second->do_magic();
    }
    

    The standard library already has a perfectly serviceable, generic idiom for handling collections and signaling presence or absence of elements, as well as combining insert-new-or-return-existing semantics. Why reinvent the wheel…

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

Sidebar

Related Questions

Scenario: An event is raised in class A that needs to be handled by
Scenario: Every page on the website will have a menu bar at the top
Scenario : I am making a clone of a popular card game. There needs
Scenario: Most smartphones have a high resolution camera that generates photos that may range
Scenario: I am calling a function that returns a field that the user enters
Scenario: An MVC3 app that uses constructor injection to provide services for a given
Scenario: A huge Patient class/entity with around 100 properties. But in the webpage I
Scenario For a multiple file uploader I am implementing, I need to have a
Scenario: I have several services that I want to be discovered by different clients.
Scenario: UserControl that has a read-only TextBox and a Button. TextBox.Text is modified and

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.