Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

jimywang

object-orientation question

This topic is 5394 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

here is my problem. in my program,there are 4 class:winmain,player,raycaster,lookuptable. either player or raycaster will contain a lookuptable in them in order to access information stored in lookuptable,so what i did is //class player #include lookuptable //class raycaster #include lookuptable and in winmain head file of both player n raycaster will be included.but when i try 2 compile it.it gives me a error saying type lookuptable redefinition.i image the reason for that is both player and raycaster has lookuptable in it,as a result in winmain,compiler will try to declare lookuptable twice. can anyone tell me a solution 2 that plz?thx.

Share this post


Link to post
Share on other sites
Advertisement
put this at the start of the lookuptable header:

#ifndef __LOOK_UP_TABLE_HEADER
#define __LOOK_UP_TABLE_HEADER


and this at the end:

#endif // __LOOK_UP_TABLE_HEADER


when the file is first encountered, it will see that __LOOK_UP_TABLE_HEADER hasn''t been defined, so it will include everything between the #ifndef and #endif. However, if the header is opened again, it will see that __LOOK_UP_TABLE_HEADER has already been defined (by the first include), and therefor it will skip the code as it is already available.

Share this post


Link to post
Share on other sites
quote:
Original post by Symphonic
or, if you are using VC++ you can put in the compiler command:

#pragma once

somewhere in each header


#pragma once is also implemented in GCC 3.4.0.

Share this post


Link to post
Share on other sites
put

#ifndef SOMEHEADERDEFINITION
#define SOMEHEADERDEFINITION


#endif

for every header file you have. not just lookup table.

Share this post


Link to post
Share on other sites
quote:
Original post by MENTAL
#ifndef __LOOK_UP_TABLE_HEADER
#define __LOOK_UP_TABLE_HEADER


You might want to stay away from defines or identifiers starting with double underscores, those are used by the compiler for internal names (as are names starting with a single underscore and a capital letter). Chances are no compiler uses __LOOK_UP_TABLE_HEADER, but if you use heaps of these you might at some point run into some weird, hard to find bugs.

Share this post


Link to post
Share on other sites

  • 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!