Jump to content
  • Advertisement
Sign in to follow this  
eal

base class needed in multiple headers

This topic is 4558 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
Advertisement
Both headers should be able to include physics.h unless physics.h includes either of the other headers, otherwise known as cyclic inclusion.

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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!