Sign in to follow this  

base class needed in multiple headers

This topic is 4340 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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;"?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.)

Share this post


Link to post
Share on other sites

This topic is 4340 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this