tags:

views:

69

answers:

2

I have been making several games with the Allegro API and C++. I have also been putting all my classes in 1 big main.cpp file. I tried many times to make .h and .cpp files, but my big problem is I have trouble with #including at the right place. For example, I want all my classes to access the allegro library without #including allegro.h everywhere. Could someone please explain how to correctly #include things. In .Net, everything seems to come together, but in c++ one thing cannot be used before it is included. Is there also a way to globally include something throughout my entire program? Thanks

+1  A: 

I want all my classes to access the allegro library without #including allegro.h everywhere.

Why? That is how you do it in C++ land.

Could someone please explain how to correctly #include things. In .Net, everything seems to come together, but in c++ one thing cannot be used before it is included

Conceptually, in .NET, it is not much different at all. You still have to place "using " at the top. The difference there is that, in .NET, you could also write this every time if you wanted to:

void Foo( System.Drawing.Drawing2D.BitmapData bData ) { }
Ed Swangren
A: 

A common way to do this is to have a master include file that includes all of the others in the correct order. This works especially well if you use precompiled headers so

in precomp.h

#include <stdio.h>
#include <allegro.h>
.. etc.

in myfile.cpp

#include "precomp.h"

in myfile2.cpp

#include "precomp.h"

and so on.

John Knoeller