Putting it all together: How to best arrange C++ source and header files
Covers the basics of what you need to do to share globals across multiple files.
Here is my basic model that I use in all my applications:
------------------------------------------------------------------------------
Globals.h is the only header file included in any source file - here is how
it's set up inside:
------------------------------------------------------------------------------
#ifndef MadeIncludes //if we haven't done this where this file can see it, then...
#define SCREENX = 640
#define SCREENY = 480
//and other app-wide #defines
#include <windows.h>
#include <ddraw.h>
//and other system or lib includes
#include "creature.h" //class header or some function prototypes
enum Enumeration{E_THINGY1, E_THINGY2};
#define MadeIncludes
#endif
extern int globalint;
extern char globalstring[50];
//and other globals
------------------------------------------------------------------------------
Winmain.cpp (or other main() or winmain() module)
------------------------------------------------------------------------------
#include "globals.h"
int globalint;
char globalstring[50];
//and other globals
//and then the rest of the main file's source code
------------------------------------------------------------------------------
Creature.cpp is my implementation for Creature.h that's included in globals.h
------------------------------------------------------------------------------
#include "globals.h" //you see, this now has access to all globals and header files
class creature
{
int x;
int y;
//whatever
};
//and other classes/structs
void MoveCreature(int newx, int newy);
//and other various procedures
------------------------------------------------------------------------------I hope this helped you guys. Questions, comments, whatever, e-mail me at [email="benbeandogdilts@cs.com"]benbeandogdilts@cs.com[/email]. Visit my web page at www.geocities.com/benbeandogdilts. Have fun, guys!
Related Tutorials
Balancing Game Development and Creative Direction in Indie Production
A practical look at how indie developers can balance creative direction with hands-on game development. This article co…
My Unreal Engine Development Process: From Core Idea to Playable Build
A practical overview of my Unreal Engine development process, covering how I move from a core game idea to a playable b…
Introducing LaneGraph: The Ultimate Road Network Solution for Unity
Discover the power of LaneGraph, a lightweight and flexible lane-based navigation system for Unity. LaneGraph makes it…
Retargeting Mixamo Characters with Root Motion In Unreal Engine 5.4.
I have always found Retargeting Mixamo Characters To have Root Motion is a serious lengthy Tast, Recently I stumbled up…
How To Make A SIMPLE Main Menu In Unity
In this tutorial for unity, i go over how to make a simple main menu for unity, it's an unlisted video because i do not…
Guide to Gameplay Balance
A perspective on competitive gameplay balance, from a background of "shooter" sandbox design.
Discussion
More from Ben Dilts
Comparing Shadow Mapping Techniques with Shadow Explorer
New Incentives and a Whole New Platform From The Intel AppUp developer program
The final installment in this series on Intel's AppUp program details additional incentives and opportunities for devel…
The Game Maker
This book excerpt contains the first chapter of the book that introduces beginning game developers to the Game Maker pr…
Discussion