   Multiple source files and global variables question
  I have a question concerning organization of code along multiple source files, and specifically the notion of global variables across multiple files.This is a simplified model of my project://d3dUtil.h ,something like globals.h generally//so basically everything other files need to run#include <d3d9.h>#include <d3dx9.h>#include <dxerr9.h>#include <string>#include <sstream>#include <vector>#include <list>Class D3Dapp;extern D3DApp* gd3dApp;extern IDirect3DDevice9* gd3dDevice;//d3dApp.hinclude "d3dUtil.h"class D3DApp{  variables  methods...}//directInput.h#include <dinput.h>...-declarations for handling input//Sphere.hclass Sphere{-vars and methods lide 'center' or 'circumference' and 'build vertexbuffer'}//directInput.cpp#include "d3dUtil.h"#include "DirectInput.h"#include "d3dApp.h"-definition of methods for handlig input//d3dApp.cpp#include "d3dApp.h"-holds definition of methods from d3dApp.h etc//Sphere.cpp-holds definition of methods for sphere class declared in sphere.h//CollisionSim.cpp#include "d3dApp.h"#include "vertex.h"etc-this is where most of the actual work is calculated, drawing multiple objects, calculating collisions, responses etcthis file needs access to everything!So my question is this: how to ogranize my code and how do i define global access for every object(of n objects, they are dynamically created) of the Sphere class? And on top of that i need global access for the list that binds all these object, and also for the iterator! Here they are:std::list<Sphere> list_of_classes;std::list<Sphere>::const_iterator iteratorI would be content only to have access to these objects and list in one of the files, namely collisionsim.cpp since most of the work is done here. So, if you need a more general view of my problem, how do i to this:I want a file to hold the declaration of my class, Sphere.h, then a Sphere.cpp which defines the sphere class, and  i want a certain other file to be able to declare objects of this class!Also i need access to the list and iterator in this file!If anyone can help me, it would be appreciated, i've tried this for some time now, but to no avail. Also some good articles on this subject would be cool!thanks!   
  I think you may find this article useful.   ;  thx alot, ill have a look! btw congratz on the 6000th post:)   ;  About globals, i'll be blunt, avoid them like a plague. You'll get clearer picture of dependencies and you dont have to think about what changes what under the hood. And in long run I'd argue you'll be better programmer aswellAlways think about who logically owns the resource, top level being the main() function, and pass on whatever functions or classes need. If the argument list grows to a mess, it's a sign to refactor something.   ;  Moving to For Beginners, since there's a pretty standard FAQ-y answer. :)   