What's the best way to have a variable be accessible from anywhere in your program?
<p>I'm making a game right now and pretty much everything has its own class. The main classes I feel that I have a problem with are my 'Level' and 'Object' class. The level class contains images to every image in the level, and the Object class contains the image for each object on the screen(an object is pretty much anything: your player, an enemy, an item, etc).</p>

<p>The way I have it right now is that the Object class has an Image and when you create a new object, you load a new image into it. So lets say you have two enemies that use the same image, both instances of the object will separately load the image and I'll have two of the same images in memory. This seems like a really bad idea and later when my game gets more complicated it will slow it down a lot.</p>

<p>So what I was thinking about doing is having something like a Resource Manager class that would hold all of the images, and than each object would just ask the resource manager for the image it needs. That way it would only store each image once and save some space.</p>

<p>I could probably easily do this with a static variable in the Object class, but since the Level class also needs to use images it would also need access to the Resource Manager. Would it be best to send a pointer to a resource manager to each instance of an object/level(or any other class I later make that would need it) and access it that way? Or would there be a better way to do this?</p>
