base class needed in multiple headers
In my curent game project there is a base class known as physics_obj defined in physics.h. It contains the basic physics variables and functions needed by things like projectiles and players. But if both players.h and projectiles.h need acess to physics_obj, how can I do this without causing redefinition errors? Is there something like "extern class physics_obj;"?
Both headers should be able to include physics.h unless physics.h includes either of the other headers, otherwise known as cyclic inclusion.
Traditional way is to add:
#ifndef HEADERNAME_H
#define HEADERNAME_H
// Code
#endif // HEADERNAME_H
This works on all compilers and basicly says, if this file has not be done, do it. If it has, skip what's inside the #ifndef.
#ifndef HEADERNAME_H
#define HEADERNAME_H
// Code
#endif // HEADERNAME_H
This works on all compilers and basicly says, if this file has not be done, do it. If it has, skip what's inside the #ifndef.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement