base class needed in multiple headers

Started by
4 comments, last by Zahlman 18 years, 2 months ago
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;"?
Advertisement
Both headers should be able to include physics.h unless physics.h includes either of the other headers, otherwise known as cyclic inclusion.
Use "#pragma once" in the physics.h file.
屋根を固定するために何パンケーキそれは取るか。紫色、ヘビに足がないばい。
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.
great, thanks all.
Stop, and read this. Chances are good you'll run into more problems fairly soon if you don't take the time to study the whole topic of "getting stuff to link properly". (Don't worry: for normal situations, there are only a few rules.)

This topic is closed to new replies.

Advertisement